版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/github_33905879/article/details/52778329
此属性一般解决lisview中嵌套按钮而出现的点击时间冲突问题。
官方文档描述如下:
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.
属性的值有三种:
beforeDescendants:viewgroup会优先其子类控件而获取到焦点
afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点
blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点
如果遇到Listview和Button点击事件冲突就在item布局的根布局添加次属性(android:descendantFocusability),一般选afterDescendants把布局中按钮添加属性android:focusable=”false”,最后在相应地方添加按钮的点击监听事件就可以避免冲重点内容突,实现item及内部按钮都可点击不冲突的效果。