我在画布上绘制了一个 shapedrawables,我想在触摸事件中检测触摸了哪些形状。无需按 (x,y) 计算,就像 html 中存在的那样自动计算。谢谢!:)
我成功地绘制了形状,并阅读了很多关于如何通过使用 (x,y) 计算来检测 ontouch 的内容,但如果我有可能自动检测到触摸的形状,那么这样做并不聪明。如果我不能用画布做到这一点,我会很高兴听到我如何绘制形状并使用 android 中的其他小部件检测触摸的形状。
public class CanvasView extends View implements View.OnTouchListener
{
private List<ShapeDrawable> shapes;
private ShapeDrawable currentCircle;
public CanvasViewenter code here(Context context, @Nullable AttributeSet attrs)
{
super(context, attrs);
setFocusable(true);
setFocusableInTouchMode(true);
this.setOnTouchListener(this);
this.shapes = new ArrayList<>();
}
@Override
protected void onDraw(final Canvas canvas)
{
super.onDraw(canvas);
}
@Override
public boolean onTouch(View view, MotionEvent motionEvent)
{
//here I want to get all the shapes that have been touched
List<ShapeDrawable> touchedShapes = null;
return true;
}
}