Recyclerview Steals Focus When Inside a Nestedscrollview

RecyclerView steals focus when inside a NestedScrollView

Make your top view focusable. "RecyclerView has "focusableOnTouchMode" set to true to handle its childrens' focus changes during layout." Relevant discussion of the issue.

Example:

<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical">

<View
android:id="@+id/someView"
android:layout_width="wrap_content"
android:layout_height="350dp"/>

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

</LinearLayout>
</android.support.v4.widget.NestedScrollView>

How to remove focus from RecyclerView inside ScrollView?

This problem because of recyclerView has default focus.

Solution

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">

Add android:descendantFocusability="blocksDescendants" to your immediate layout of scrollView

Android prevent nested recyclerview from automatically repositioning

you can add this attribute to your linear layout. The Linear Layout direct child of your scrollView.

    android:descendantFocusability="blocksDescendants"


Related Topics



Leave a reply



Submit