标签:
注:本文改写自李华明的博客,原文地址:http://blog.csdn.net/xiaominghimi/article/details/6089317
一、设置全屏:
两种方法,第一种在activity中:
package com.howlaa.androidgame1; import android.os.Bundle; import android.view.Window; import android.view.WindowManager; import android.app.Activity; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //隐藏掉电池等信息 this.requestWindowFeature(Window.FEATURE_NO_TITLE); //隐藏掉标题栏 setContentView(new MyView(this)); } }
android:theme="@android:style/Theme.NoTitleBar" 隐去标题栏android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 隐去状态栏
二:画简单图形:
新建一个类,继承view
package com.howlaa.androidgame1; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.RectF; import android.view.View; public class MyView extends View{ private Paint paint; public MyView(Context context){ super(context); paint = new Paint(); paint.setAntiAlias(true);//设置画笔无锯齿(如果不设置可以看到效果很差) this.setKeepScreenOn(true);//设置背景常亮 paint.setColor(Color.RED); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(Color.WHITE);//设置画布颜色 Rect rect = new Rect(30, 30, 50, 50);//前两个参数是左上角的坐标,后两个参数是右下角坐标 canvas.drawRect(rect, paint);//画出 RectF rectF = new RectF(70f,30f,90f,90f);//RectF是矩形的float形式,精确度和Rect不一样 canvas.drawArc(rectF,0,360,true,paint); canvas.drawCircle(150, 30, 20, paint); //注意,这个points必须的长度必须为4的倍数,因为4个为一组,一组的前两个参数为线的开始坐标,后两个参数为线的终点坐标 float[] points =new float[]{200f,10f,200f,40f,300f,30f,400f,70f}; canvas.drawLines(points, paint); canvas.drawText("hello", 230, 30, paint); } }
标签:
原文地址:http://blog.csdn.net/howlaa/article/details/43731753