/**
* Called when the activity is first created
*/
@Override
protected void onCreate(Bundle instance)
{
super.onCreate(instance);
setContentView(new TouchMotionView(this));
}
/**
* 思路:先加载类,继承view
* 定义半径,x、y轴 , Paint绘画工具对象、action_value Motion Action值
* 构造对象,初始化x、y轴 ,action_value
* 初始化画布
* 定义onTouchEvent事件处理
*
* 触屏控制显示画布 在画布上绘制小球
*
* @author mickey
* @version 1.0, 2012-8-2
* @since NLP V100R001C01
*/
private class TouchMotionView extends View
{
private int RADIUS = 10;
private Paint myPaint = new Paint();
private int action_value;
private float x_value, y_value;
/**
* constructor
*
* @param
* @throws
* @since NLP V100R001C01
*/
public TouchMotionView(Context context)
{
super(context);
action_value = MotionEvent.ACTION_UP;
x_value = 0;
y_value = 0;
}
/**
* 获取坐标点 在画布上绘制小球
* @param canvas
*/
@Override
protected void onDraw(Canvas canvas)
{
Paint paint = myPaint;
canvas.drawColor(R.color.red);
if (MotionEvent.ACTION_MOVE == action_value) // 移动动作
{
paint.setColor(Color.RED);
}
else if (MotionEvent.ACTION_UP == action_value) // 抬起动作
{
paint.setColor(Color.WHITE);
}
else if (MotionEvent.ACTION_DOWN == action_value) // 按下动作
{
paint.setColor(Color.GREEN);
}
canvas.drawCircle(x_value, y_value, RADIUS, paint); //半径长度
setTitle("Action = " + action_value + " ["+ x_value +","+ y_value +"]");
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
action_value = event.getAction(); // 获得动作
x_value = event.getX(); // 获得坐标
y_value = event.getY();
invalidate(); // 重新绘制
return true;
}
}
* Called when the activity is first created
*/
@Override
protected void onCreate(Bundle instance)
{
super.onCreate(instance);
setContentView(new TouchMotionView(this));
}
/**
* 思路:先加载类,继承view
* 定义半径,x、y轴 , Paint绘画工具对象、action_value Motion Action值
* 构造对象,初始化x、y轴 ,action_value
* 初始化画布
* 定义onTouchEvent事件处理
*
* 触屏控制显示画布 在画布上绘制小球
*
* @author mickey
* @version 1.0, 2012-8-2
* @since NLP V100R001C01
*/
private class TouchMotionView extends View
{
private int RADIUS = 10;
private Paint myPaint = new Paint();
private int action_value;
private float x_value, y_value;
/**
* constructor
*
* @param
* @throws
* @since NLP V100R001C01
*/
public TouchMotionView(Context context)
{
super(context);
action_value = MotionEvent.ACTION_UP;
x_value = 0;
y_value = 0;
}
/**
* 获取坐标点 在画布上绘制小球
* @param canvas
*/
@Override
protected void onDraw(Canvas canvas)
{
Paint paint = myPaint;
canvas.drawColor(R.color.red);
if (MotionEvent.ACTION_MOVE == action_value) // 移动动作
{
paint.setColor(Color.RED);
}
else if (MotionEvent.ACTION_UP == action_value) // 抬起动作
{
paint.setColor(Color.WHITE);
}
else if (MotionEvent.ACTION_DOWN == action_value) // 按下动作
{
paint.setColor(Color.GREEN);
}
canvas.drawCircle(x_value, y_value, RADIUS, paint); //半径长度
setTitle("Action = " + action_value + " ["+ x_value +","+ y_value +"]");
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
action_value = event.getAction(); // 获得动作
x_value = event.getX(); // 获得坐标
y_value = event.getY();
invalidate(); // 重新绘制
return true;
}
}