Multiple horizontal RecyclerView inside NestedScrollView steal focus

Viewed 3783

Actually I'm currently working for a AndroidTV app. I have multiple horizontal RecyclerView right to left inside a NestedScrollView like that image.

Problem is that when I scroll more towards left, then focus moves to different list or different view which is not good.

I don't want the focus to change. If the list reaches to the end, then focus should remain at same position.

I tried :

android:descendantFocusability="blocksDescendants"
android:focusableInTouchMode="true" //in parent layout

But it didn't work..

Can anyone help me out ??

enter image description here

Not solved

3 Answers

Try changing your ScrollView to NestedScrollView. A reason behind this is

**NestedScrollView**

NestedScrollView is just like ScrollView, but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.

**ScrollView**

Layout container for a view hierarchy that can be scrolled by the user, allowing it to be larger than the physical display. A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects

This will help you to determine which layout is being focused.

You can use below structure for nested scroll

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:clickable="false"
    android:orientation="vertical">

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll_search_all"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

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

                <android.support.v7.widget.RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:isScrollContainer="false"
                    android:nestedScrollingEnabled="false" />

            </LinearLayout>

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

                <android.support.v7.widget.RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:isScrollContainer="false"
                    android:nestedScrollingEnabled="false" />

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

I hope this will help!

Try using this one code in your recycleview section 2:

android:layoutDirection="rtl"
Related