Android应用开发揭秘的第8个程序5_3_PaintDraw修改版和高仿版的源码注释
来源:互联网 发布:淘宝客服监控 编辑:程序博客网 时间:2024/04/27 22:21
//学会运用PaintDraw画笔
Activity01.java
package com.PaintDraw;
import android.app.Activity;
import android.os.Bundle;
public class Activity01 extends Activity
{
private GameView mGameView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mGameView = new GameView(this);
setContentView(mGameView);
}
}
GameView.java
package com.PaintDraw;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
public class GameView extends View implements Runnable
{
public final static String TAG = "Examples_05_03_GameView"; //
/* 声明Paint对象 */
private Paint mPaint = null;
public GameView(Context context)
{
super(context);
/* 构建对象 */
mPaint = new Paint();
/* 开启线程 */
new Thread(this).start();
}
public void onDraw(Canvas canvas)
{
super.onDraw(canvas);
/* 设置Paint为无锯齿 */
mPaint.setAntiAlias(true);
/* 设置Paint的颜色 */
mPaint.setColor(Color.RED);
mPaint.setColor(Color.BLUE);
mPaint.setColor(Color.YELLOW);
mPaint.setColor(Color.GREEN);
/* 同样是设置颜色 */
mPaint.setColor(Color.rgb(255, 0, 0));
/* 提取颜色 */
Color.red(0xcccccc);
Color.green(0xcccccc);
/* 设置paint的颜色和Alpha值(a,r,g,b) */
mPaint.setARGB(255, 255, 0, 0);
/* 设置paint的Alpha值 */
mPaint.setAlpha(220);
/* 这里可以设置为另外一个paint对象 */
// mPaint.set(new Paint());
/* 设置字体的尺寸 */
mPaint.setTextSize(14);
// 设置paint的风格为“空心”.
// 当然也可以设置为“实心”(Paint.Style.FILL)
mPaint.setStyle(Paint.Style.STROKE);
// 设置“空心”的外框的宽度。
mPaint.setStrokeWidth(5);
/* 得到Paint的一些属性 */
Log.i(TAG, "paint的颜色:" + mPaint.getColor());
Log.i(TAG, "paint的Alpha:" + mPaint.getAlpha());
Log.i(TAG, "paint的外框的宽度:" + mPaint.getStrokeWidth());
Log.i(TAG, "paint的字体尺寸:" + mPaint.getTextSize());
/* 绘制一个矩形 */
// 肯定是一个空心的举行
canvas.drawRect((320 - 80) / 2, 20, (320 - 80) / 2 + 80, 20 + 40, mPaint);
/* 设置风格为实心 */
mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(Color.GREEN);
/* 绘制绿色实心矩形 */
canvas.drawRect(0, 20, 40, 20 + 40, mPaint);
}
// 触笔事件
public boolean onTouchEvent(MotionEvent event)
{
return true;
}
// 按键按下事件
public boolean onKeyDown(int keyCode, KeyEvent event)
{
return true;
}
// 按键弹起事件
public boolean onKeyUp(int keyCode, KeyEvent event)
{
return false;
}
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
{
return true;
}
public void run()
{
while (!Thread.currentThread().isInterrupted())
{
try
{
Thread.sleep(100);
}
catch (InterruptedException e)
{
Thread.currentThread().interrupt();
}
// 使用postInvalidate可以直接在线程中更新界面
postInvalidate();
}
}
}
Gf_PaintDrawActivity.java
package packagename.GfPaintDraw;
import android.app.Activity;
import android.os.Bundle;
public class Gf_PaintDrawActivity extends Activity
{
private GameView mGameView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mGameView = new GameView(this);
setContentView(mGameView);
}
}
- Android应用开发揭秘的第8个程序5_3_PaintDraw修改版和高仿版的源码注释
- Android应用开发揭秘的第5个程序3_4_cycle修改版和高仿版的源码注释
- Android应用开发揭秘的第6个程序5_1_ViewDrawRect修改版和高仿版的源码注释
- Android应用开发揭秘的第7个程序5_2_SurfaceViewDrawCircle修改版和高仿版的源码注释
- Android应用开发揭秘的第9个程序5_4_canvas修改版和高仿版的源码注释
- Android应用开发揭秘的第10个程序5_5_DrawAllShape修改版和高仿版的源码注释
- Android应用开发揭秘的第11个程序5_6_DrawText修改版和高仿版的源码注释
- Android应用开发揭秘的第12个程序5_7_drawImage修改版和高仿版的源码注释
- Android应用开发揭秘的第13个程序5_8_MatrixRotateImg修改版和高仿版的源码注释
- Android应用开发揭秘的第14个程序5_9_MatrixScaleImg修改版和高仿版的源码注释
- Android应用开发揭秘的第15个程序5_10_WavePixelImg修改版和高仿版的源码注释
- Android应用开发揭秘的第16个程序5_11_ShaderImg修改版和高仿版的源码注释
- Android应用开发揭秘的第17个程序5_12_DBuffImg修改版和高仿版的源码注释
- Android应用开发揭秘的第18个程序5_13_SetFlags修改版和高仿版的源码注释
- Android应用开发揭秘的第19个程序5_14_GetDisplay修改版和高仿版的源码注释
- Android应用开发揭秘的第24个程序5_19_gif修改版和高仿版的源码注释
- Android应用开发揭秘的第3个程序3_2_Content_Provider修改版和高仿版的源码注释
- Android应用开发揭秘的第4个程序3_3_MusicService修改版和高仿版的源码注释
- TextView属性大全
- uva_10404_Bachet's Game
- WINDOWS环境下设置socket连接超时
- 屏蔽特殊字符
- Linux串口工具Minicom连接TQ2440开发板
- Android应用开发揭秘的第8个程序5_3_PaintDraw修改版和高仿版的源码注释
- oracle 自启动脚本
- 关于网页上输出当前时间的技术
- 预处理器变量小结
- uniqueidentifier 数据类型
- 11级_Java_曹建波 11.09 JavaBean与Jsp
- 谷歌能查到结果,但是跳转失败,怎么办
- 更改Android设备的键值映射
- iPhone开发之深入浅出 (7) — ARC总结