Android开发工具类:点击扩大点击区域的

释放双眼,带上耳机,听听看~!
package com.sikkha.skline.utils;
import android.graphics.Rect;
import android.view.TouchDelegate;
import android.view.View;
/**
* ================================================
*
* @author:Vip 版    本:V 5.0.0
* 创建日期:2018/8/29
* 描    述:点击扩大点击区域的工具类
* 修订历史:
* ================================================
*/
public class TouchDelegateUtils {
/**
* 增加控件的可点击范围,最大范围只能是父布局所包含的的区域
*/
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() {
@Override
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);
}
}
});
}
/**
* 还原View的触摸和点击响应范围,最小不小于View自身范围
*
* @param view
*/
public static void restoreViewTouchDelegate(final View view) {
((View) view.getParent()).post(new Runnable() {
@Override
public void run() {
Rect bounds = new Rect();
bounds.setEmpty();
TouchDelegate touchDelegate = new TouchDelegate(bounds, view);
if (View.class.isInstance(view.getParent())) {
((View) view.getParent()).setTouchDelegate(touchDelegate);
}
}
});
}
}

人已赞赏
Android文章

android开发属性动画ValueAnimator详解

2020-3-11 18:05:11

Android文章

Android开发百度地图定位功能,傻瓜式教程

2020-3-11 18:22:36

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索