本文介绍了是否有如何使用TouchDelegate在Android中增加视图的点击目标的大小的例子吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的理解是,当你有一个观点,就是太小,无法轻易触碰,你应该使用TouchDelegate增加该视图的可点击区域。

My understanding is that when you have a view that's too small to easily touch, you're supposed to use a TouchDelegate to increase the clickable region for that view.

不过,搜索用法示例在谷歌打开了多人问这个问题,但几个答案。

However, searching for usage examples on Google turn up multiple people asking the question, but few answers.

有谁知道正确的方式来建立一个触摸委托一个观点,比方说,通过4个像素在各个方向增加其点击区域?

Does anyone know the proper way to set up a touch delegate for a view to, say, increase its clickable region by 4 pixels in every direction?

推荐答案

我问一个朋友在谷歌和他们能够帮助我弄清楚如何使用TouchDelegate。下面是我们想出了:

I asked a friend at Google and they were able to help me figure out how to use TouchDelegate. Here's what we came up with:

final View parent = (View) delegate.getParent();
parent.post( new Runnable() {
    // Post in the parent's message queue to make sure the parent
    // lays out its children before we call getHitRect()
    public void run() {
        final Rect r = new Rect();
        delegate.getHitRect(r);
        r.top -= 4;
        r.bottom += 4;
        parent.setTouchDelegate( new TouchDelegate( r , delegate));
    }
});

这篇关于是否有如何使用TouchDelegate在Android中增加视图的点击目标的大小的例子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 07:45