您的位置 首页 焦点资讯

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

原文链接:https://blog.csdn.net/android_yyf/article/details/79924669?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166580747916782248574164%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=166580747916782248574164&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-19-79924669-null-null.nonecase&utm_term=%E7%84%A6%E7%82%B9

热门文章