【问题标题】:Making canvas' drawline clickable使画布的绘制线可点击
【发布时间】:2015-02-25 04:51:30
【问题描述】:

基于这个答案,我创建了一个 rectF 的 arrayList。

Technique to make a canvas drawLine() clickable?

这是我的代码的逻辑:

List<RectF> rectFs;

Point pt1;
Point pt2;

然后

path.moveTo(pt1.x, pt1.y);
path.lineTo(pt2.x, pt2.y);

path.computeBounds(rectF, true);
rectFs.add(rectF);

然后,我有这个方法来检查 clicked 和 rectF arrayList。

void lineHighighted(Point pt) {
    int ct = 0;
    for(RectF rectF : rectFs) {
        if(rectF.contains(pt.x, pt.y)) {
            ct++;
            Log.d(tag, ct + "HERE");
        }
    }
}

我的问题是,有时,即使我没有触摸那条“线”,也会选择或“调用”整个数组列表。

我的代码有什么问题吗?

提前致谢。

附加:

我发现在我的画布中添加此代码后:

path.moveTo(coor1[0], coor1[1]);
path.lineTo(coor2[0], coor2[1]);
canvas.drawPath(path, paint2);
path.computeBounds(rectf, true);

我之前的结果:

它变成了这样:

【问题讨论】:

    标签: java android canvas touch-event


    【解决方案1】:

    可能是这样!因为我没有看到您与画布交互的代码,所以我会发布完全正常工作的代码。逻辑是一行不能覆盖另一行,以防功能正常。希望我能帮助你.

        // setting where I will draw the ImageView for taking pictures
    
        // rec is used for onInterceptTouchEvent. I pass this from the
        // highest to lowest layer so that when this area of the screen
        // is pressed, it ignores the TouchView events and passes it to
        // this activity so that the button can be pressed.
        rec.set((int)((double)mScreenWidth*.85),
                (int)((double)mScreenHeight*.10) ,
                (int)((double)mScreenWidth*.85)+mButtonDrawable.getMinimumWidth(), 
                (int)((double)mScreenHeight*.70)+mButtonDrawable.getMinimumHeight());
        mButtonDrawable = null;
    

    通过这个逻辑,你可以在这个逻辑中使用任何你想要的东西,它可以让点击发生而不被覆盖

    【讨论】:

    • 感谢先生的回答。对此,我真的非常感激。如果您可以检查我在顶部的附加问题,可以吗?在此先感谢:)
    • 对不起,我无法加载您的图片,您可以重新上传它们吗?请:)
    • 我发现了问题。 stackoverflow.com/questions/27697251/… 就像 path.computebounds(rectf, true) 是问题所在。你遇到过吗?
    • 哦,不,我从来没有遇到过这个问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多