キャンバスに shaperawables を描画し、タッチ イベントでどの図形がタッチされたかを検出したいと考えています。(x,y)で計算せずに、html に存在するように自動的に..ありがとう! :)
形状の描画に成功し、(x,y) で計算してオンタッチを検出する方法について多くのことを読みましたが、タッチされた形状を自動的に検出できる可能性がある場合、それを行うのは賢明ではありません。キャンバスでそれができない場合は、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;
}
}