我的理解是,当您的视图太小而无法轻松触摸时,您应该使用 TouchDelegate 来增加该视图的可点击区域。
然而,在谷歌上搜索使用示例时,发现很多人都在问这个问题,但答案却很少。
有谁知道为视图设置触摸委托的正确方法,例如,在每个方向上将其可点击区域增加 4 个像素?
我问了 Google 的一位朋友,他们帮助我弄清楚如何使用 TouchDelegate。这是我们的想法:
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));
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)