通过查找google官方提供的Api文档的ViewGroup类查看下面源码
public void setDescendantFocusability (int focusability)
Set the descendant focusability of this view group. This defines the relationship between this view group and its descendants when looking for a view to take focus in requestFocus(int, android.graphics.Rect)
.
Parameters
focusability | one of FOCUS_BEFORE_DESCENDANTS , FOCUS_AFTER_DESCENDANTS , FOCUS_BLOCK_DESCENDANTS . |
---|
FOCUS_BEFORE_DESCENDANTS 在子控件前获取焦点;
FOCUS_AFTER_DESCENDANTS 在子控件之后获取焦点;
FOCUS_BLOCK_DESCENDANTS 阻止任何的子控件获得焦点,即使他们是focusable。
解决监听事件冲突的方法:
在ListView的Item布局xml文件中进行如下的设置
android
:descendantFocusability=
"blocksDescendants"
的属性
?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#fd6563" android:descendantFocusability="blocksDescendants">
// ....子控件
这样ListView的Item布局子控件与Item的setOnItemClickListenter监听事件都能生效了</RelativeLayout>