使用TouchDelegate扩大View的点击区域
来源:互联网 发布:虚拟主机 阿里云 编辑:程序博客网 时间:2024/04/28 01:41
TouchDelegate可以增大view的可点击区域。当view较小时,TouchDelegate就派上用场了。
TouchDelegate使用非常简单,只需要几行代码:
private static class TouchDelegateLayout extends FrameLayout {private CheckBox checkBox;public TouchDelegateLayout(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);init();}public TouchDelegateLayout(Context context, AttributeSet attrs) {super(context, attrs);init();}public TouchDelegateLayout(Context context) {super(context);init();}private void init() {checkBox = new CheckBox(getContext());FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);params.gravity = Gravity.CENTER;addView(checkBox, params);
<span style="white-space:pre"></span>/* 使用post runnable的方式去设置Delegate区域大小的原因是,如该View师在Activity的OnCreate()或Fragment的OnCreateView()中绘制,此时UI界面尚未开始绘制,无法获得正确的坐标; */post(new Runnable() {@Overridepublic void run() {Rect bound = new Rect();TouchDelegateLayout.this.getHitRect(bound);TouchDelegate delegate = new TouchDelegate(bound, checkBox);TouchDelegateLayout.this.setTouchDelegate(delegate);}});}}
0 0
- 使用TouchDelegate扩大View的点击区域
- 使用TouchDelegate扩大View的点击区域
- 使用android.view.TouchDelegate扩大View的触摸点击区域
- 使用android.view.TouchDelegate扩大View的触摸点击区域
- 用 TouchDelegate 扩大子 View 的点击区域
- Android TouchDelegate 扩大点击区域
- Android笔记之利用TouchDelegate扩大View点击区域
- 使用 TouchDelegate 扩大控件的点击范围
- Android 扩大触摸的触发区域 TouchDelegate
- Android学习之 扩大控件点击触摸区域及TouchDelegate的介绍
- TouchDelegate 来增大按钮的点击区域
- 扩大Button的点击区域
- 扩大UIButton的点击区域
- 扩大控件的点击区域
- 扩大checkbox的点击区域
- css~使用css扩大可点击区域
- Android 扩大ImageView的点击区域
- Android 扩大ImageView的点击区域
- android:BroadcastReceiver 广播接收者
- Nginx安装部署
- java 并发工具类CyclicBarrier介绍
- 像蚂蚁一样工作,像蝴蝶一样生活
- Perl和Python的比较(主要是性能比较)
- 使用TouchDelegate扩大View的点击区域
- maven 项目部署
- java执行其他软件的命令
- liunx 定时任务
- Android安卓中图片压缩
- 理解串口流控
- RWTHLM 源码分析(四)之rnn结构
- 生活自勉
- 获取一个区间内的随机数