android:descendantFocusability用法简析
来源:互联网 发布:历史书籍推荐 知乎 编辑:程序博客网 时间:2024/06/15 20:45
开发中很常见的一个问题,项目中的listview不仅仅是简单的文字,常常需要自己 定义listview,自己的Adapter去继承BaseAdapter,在adapter中按照需求进行编写,问题就出现了,可能会发生点击每一个 item的时候没有反应,无法获取的焦点。原因多半是由于在你自己定义的Item中存在诸如ImageButton,Button,CheckBox等子 控件(也可以说是Button或者Checkable的子类控件),此时这些子控件会将焦点获取到,所以常常当点击item时变化的是子控件,item本 身的点击没有响应。
这时候就可以使用descendantFocusability来解决啦,API描述如下:
android:descendantFocusabilitya
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点击的灵异事件告一段落。
- android:descendantFocusability用法简析
- android:descendantFocusability用法简析
- android:descendantFocusability用法简析
- android:descendantFocusability用法简析
- android:descendantFocusability用法简析
- android:descendantFocusability用法简析
- android:descendantFocusability用法简析
- android:descendantFocusability用法简析
- android:descendantFocusability用法简析
- android:descendantFocusability用法简析
- android:descendantFocusability用法简析
- android:descendantFocusability用法简析
- android:descendantFocusability用法简析
- android:descendantFocusability用法简析
- android:descendantFocusability用法简析
- android:descendantFocusability用法简析
- android:descendantFocusability用法简析
- android:descendantFocusability用法简析
- 调用函数,输出乘法口诀表(正三角形和倒三角形),自己定义口诀表的行和列
- CentOS 7 安装MySQL
- STL源码---allocator配置器
- 读书笔记(二)——《Java核心技术卷一》第三章Java的基本程序设计结构
- 一篇超强超详细的并查集详解
- android:descendantFocusability用法简析
- Linux之Keepalived实现高可用
- 输入一个数,输出星号三角的的几种情况
- 备忘录模式 | Memento Pattern
- CDQ分治小结
- Hadoop-No.8之时间戳
- syntax error : unexpected end of file 问题的解决
- MyBatis与JDBC的比较
- 百炼-2694-逆波兰表达式-C语言-递归