android开发如何增大控件的可点击区域

来源:互联网 发布:网络直播现状分析 编辑:程序博客网 时间:2024/05/18 00:23

   在项目开发工程中,发现有时控件比较小,比如checkBox,ImageView等等,此时需要增大控件的可点击区域:
/** * 增加控件的可点击范围,最大范围只能是父布局所包含的的区域 */public static void addDefaultScreenArea(final View view, final int top,final int bottom,final int left,final int right) { // 增大checkBox的可点击范围final View parent = (View) view.getParent();parent.post(new Runnable() {public void run() { Rect bounds = new Rect();                  view.setEnabled(true);                  view.getHitRect(bounds);                    bounds.top -= top;                  bounds.bottom += bottom;                  bounds.left -= left;                  bounds.right += right;                    TouchDelegate touchDelegate = new TouchDelegate(bounds, view);                    if (View.class.isInstance(view.getParent())) {                      ((View) view.getParent()).setTouchDelegate(touchDelegate);                  }  }});}

   发现这里的解释更加详细,可参考:http://blog.csdn.net/tongcpp/article/details/23450975

0 0