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

 
  1.  在项目开发工程中,发现有时控件比较小,比如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

猜你喜欢

转载自blog.csdn.net/qq_33523706/article/details/81511079
今日推荐