我有自定义视图,并在该customView类中重写onTouchEvent。我想在点击customView时显示三个弧。我已经实现了以下代码来处理该视图上的点击事件。
@Override
public boolean onTouchEvent(final MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_UP) {
Paint p = new Paint();
RectF rectF = new RectF(50, 50, 500, 500);
p.setColor(Color.BLACK);
canvas.drawArc(rectF, 0, 45, true, p);
canvas.drawArc(rectF, 145, 45, true, p);
canvas.drawArc(rectF, 260, 45, true, p);
invalidate(50, 50, 500, 500);
return performClick();
}
return true;
}
请说明我做了什么错误。
答案 0 :(得分:0)
为什么在点击完成后需要调用performClick()? 如果处理了事件,则应返回true,否则返回false。所以我认为核心变体应该是
@Override
public boolean onTouchEvent(final MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_UP) {
Paint p = new Paint();
RectF rectF = new RectF(50, 50, 500, 500);
p.setColor(Color.BLACK);
canvas.drawArc(rectF, 0, 45, true, p);
canvas.drawArc(rectF, 145, 45, true, p);
canvas.drawArc(rectF, 260, 45, true, p);
invalidate(50, 50, 500, 500);
return true;
}
return false;
}