【问题标题】:I want to show a multiple circle on image view particular coordinates我想在图像视图特定坐标上显示多个圆圈
【发布时间】:2019-07-02 13:06:35
【问题描述】:

我想在图像视图特定坐标上显示一个多圆,当单击该圆时,它将返回有关该圆坐标的信息并显示 2 个按钮 在android中可能吗 如果可能的话,给我一个关于如何设置该圈子的点击事件的建议

【问题讨论】:

  • 这里不能直接索要代码。你需要展示你的努力和帮助解决错误。
  • 我尝试使用画布绘制在图像上绘制圆圈,但我无法理解如何在该圆圈上设置点击事件
  • 不直接绘制。为此使用 CustomView。
  • 我是安卓新手,如果你知道请帮助我
  • 检查 tutorial 关于 CustomView。

标签: android


【解决方案1】:

您不能为绘制的圆圈设置onClick 事件。

您应该将onClick 事件设置为您的ImageView 对象。更好的是,设置一个onTouch 事件。然后,将所有圆圈及其坐标保存在一个列表中。

onTouch 监听器中搜索您的列表以测试您的点击是否在圆圈内。

imageView1.setOnTouchListener(new OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        int action = event.getAction();
        switch (action) {
        case MotionEvent.ACTION_DOWN:
            float downx = event.getX();
            float downy = event.getY();
            // downx, downy => coordinates for click
            // with these coordinates you can search in you list to find the circle
            break;
        case MotionEvent.ACTION_MOVE:
            break;
        case MotionEvent.ACTION_UP:
            break;
        default:
            break;
        }
        return true;
    }
});

【讨论】:

  • 对不起先生,我在这里有点混淆了如何使用列表
  • @SAGARADKHALE 请分享你是如何画圆圈的。
【解决方案2】:

您可以使用 ConstraintLayout 在任何地方显示任何类型的视图并获取该视图的点击事件:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-27
    • 2016-02-09
    • 2019-09-23
    • 2016-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多