我在RelativeLayout中有3个LinerLayouts,每个LinerLayouts包含9个按钮。 现在我想在触摸按钮的同时在按钮顶部绘制矩形框,并且矩形框应该滑动(移动)到每个按钮手指的移动方式。知道如何做到这一点..提前谢谢。
答案 0 :(得分:0)
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawRect(mRect, new Paint());
}
private Rect mRect = new Rect();
private static final int WIDTH = 100;
private static final int HEIGHT = 100;
private void setRectPosition(int x, int y) {
mRect.set(x, y, WIDTH, HEIGHT);
invalidate();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
setRectPosition((int)x, (int)y);
return super.onTouchEvent(event);
}
我认为这可行。