解决Recycler的item抢夺焦点的问题:
在RecyclerView的直属父布局添加
android:focusable="true" android:focusableInTouchMode="true"
注意是直属父布局,如下面代码展示是给LinearLayout添加,并不是给跟布局RelativeLayout
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" >
<LinearLayout android:focusable="true"//关键代码1 android:focusableInTouchMode="true"//关键代码2 android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView android:descendantFocusability="afterDescendants" android:layout_width="match_parent" android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView> </LinearLayout> </RelativeLayout>