我需要为我设置的矩形设置一个 onTouch 方法,但我不知道如何在 OnDraw 方法中执行此操作。这但我不知道我的代码如何,感谢您的帮助!
public class Tab3 extends View implements OnTouchListener
{
int x1, x2, y1, y2;
Rect Rect = new Rect();
public Tab3(Context context, AttributeSet attrs)
{
super (context, attrs);
x1 = 0;
x2 = 100;
y1 = 0;
y2 = 100;
}
@Override
protected void onDraw(Canvas canvas)
{
// TODO Auto-generated method stub
super.onDraw(canvas);
Rect.set(x1, y1, x2, y2);
Paint blue = new Paint();
blue.setColor(Color.BLUE);
canvas.drawRect(Rect, blue);
}
@Override
public boolean onTouch(View v, MotionEvent event)
{
return false;
}
}