【发布时间】:2019-02-02 12:24:43
【问题描述】:
我在画布上绘制了一个 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;
}
}
【问题讨论】:
标签: android android-canvas shapes ontouch shapedrawable