容器与子类焦点优先——descendantFocusability
来源:互联网 发布:网络 无标度 编辑:程序博客网 时间:2024/06/06 04:35
开发中很常见的一个问题,项目中的listview不仅仅是简单的文字,常常需要自己定义listview,自己的Adapter去继承BaseAdapter,在adapter中按照需求进行编写,问题就出现了,可能会发生点击每一个item的时候没有反应,无法获取的焦点。原因多半是由于在你自己定义的Item中存在诸如ImageButton,Button,CheckBox等子控件(也可以说是Button或者Checkable的子类控件),此时这些子控件会将焦点获取到,所以常常当点击item时变化的是子控件,item本身的点击没有响应。
这时候就可以使用descendantFocusability来解决啦,API描述如下:
android:descendantFocusability
Defines the relationship between the ViewGroup and its descendants when looking for a View to take focus.
Must be one of the following constant values.
该属性是当一个为view获取焦点时,定义viewGroup和其子控件两者之间的关系。
属性的值有三种:
beforeDescendants:viewgroup会优先其子类控件而获取到焦点
afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点
blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点
通常我们用到的是第三种,即在Item布局的根布局加上android:descendantFocusability=”blocksDescendants”的属性就好了,至此listview点击的灵异事件告一段落。心得:遇到不会不懂的地方除了网上查询资料之外,也可以多多去尝试每种属性的作用,多阅读官方文档(我始终觉得还是读原文的比翻译的理解的会更好)。
- 容器与子类焦点优先——descendantFocusability
- android:descendantFocusability——父容器和子控件的焦点获取问题
- android:descendantFocusability——父容器和子控件的焦点获取问题
- android:descendantFocusability——父容器和子控件的焦点获取问题
- Android 容器焦点设置 android:descendantFocusability
- android:descendantFocusability 焦点 父控件与子控件焦点
- android:descendantFocusability 焦点 父控件与子控件焦点
- android:descendantFocusability 焦点 父控件与子控件焦点
- android:descendantFocusability焦点
- 容器适配器—优先队列
- ACM学习历程19——queue队列容器与priority_queue优先队列容器
- ListView 属性详解 - 焦点 descendantFocusability
- STL容器——优先队列
- android:descendantFocusability用法简析-ListView与Button、RadioButton焦点冲突问题
- android:descendantFocusability 参数解决焦点大问题
- queue容器与priority_queue(优先队列)
- STL序列式容器之优先队列——priority_queue
- descendantFocusability
- iOS开发之CFMutableDictionaryRef 转 NSDictionary (__bridge NSDictionary *)
- 分布式系统 服务 的稳定性
- Swift学习之六:元组(Tuples)
- boost::filesystem使用手册
- 一次心脏滴血漏洞的bug处理过程
- 容器与子类焦点优先——descendantFocusability
- Android屏幕录制AS自带功能
- [软件人生]关于风险管理和风险应急解决的事情的再次提示
- setsockopt :SO_LINGER 选项设置
- targetSdkVersion
- 正确的获得一个view的宽和高(两种方法)
- hello world
- 未来已来
- Leetcode Word Ladder