解决RecyclerView抢夺焦点

解决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>

    原文作者:_YYF
    原文地址: https://blog.csdn.net/android_yyf/article/details/79924669
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞