增加Android应用程序的Tap区域

时间:2014-08-27 08:46:33

标签: android sqlite opengl-es

我正在开发一个Android应用程序。这与全球相同。我想设置点击地球上提到的点(城市)。我也有地球上提到的要点的数据库(纬度,长度和其他数据)。我想要的功能是,当我点击地球时,我想搜索纽约市,它得到了纽约市的长途,并从数据库中提供了所有细节。问题是我设置了数据库,但是当我点击地球时它不会给我详细信息,所以我想增加点击区域。

1 个答案:

答案 0 :(得分:0)

如果是VIEW对象,这可能会有所帮助:

public static void increaseClickArea(View parent, View child) {
    // increase the click area with delegateArea, can be used in + create
    // icon
    final View chicld = child;
    parent.post(new Runnable() {
        public void run() {
            // Post in the parents message queue to make sure the
            // parent
            // lays out its children before we call getHitRect()
            Rect delegateArea = new Rect();
            View delegate = chicld;
            delegate.getHitRect(delegateArea);
            delegateArea.top -= 600;
            delegateArea.bottom += 600;
            delegateArea.left -= 600;
            delegateArea.right += 600;
            TouchDelegate expandedArea = new TouchDelegate(delegateArea,
                    delegate);
            // give the delegate to an ancestor of the view we're
            // delegating the
            // area to
            if (View.class.isInstance(delegate.getParent())) {
                ((View) delegate.getParent())
                        .setTouchDelegate(expandedArea);
            }
        };
    });
}