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.
Constant | Value | Description |
---|---|---|
beforeDescendants | 0 | The ViewGroup will get focus before any of its descendants. 父控件优先获取 |
afterDescendants | 1 | The ViewGroup will get focus only if none of its descendants want it. 子控件优先获取 |
blocksDescendants | 2 | The ViewGroup will block its descendants from receiving focus. 屏蔽子控件获取控件 |
This corresponds to the global attribute resource symbol descendantFocusability
.
在ListView有Button等需要被点击的控件,如果不对相关属性进行设置,ListView的item点击事件将不能响应。ListView中的Button等控件需要每个Item都绑定一次,不然触发的时候会得不到想要的结果。
解决的办法,在ListView的Item的xml文件中添加如下属性:
1)添加android:descendantFocusability="blocksDescendants"
2)Button添加属性android:focusable="false"和android:clickable="true"
这样设置后ListView和Item中的Button都具有Click的功能。
点击Button后Item变色 以此类推 这个还在研究中....