Nested scrollview + recyclerview, weird autoscroll behavior

In the pager view, I have several fragments, one of them uses a nested scrollview with a header and recyclerview:

<android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/scrollview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.m360.android.fragment.Members.MemberDetailsFragment">

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

        <header/>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="false"
            android:paddingTop="0dp" />

    </LinearLayout>

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

The header tag is a complex layout that I did not want to publish here, as it greatly expands the code.

when I switch between tabs, it scrolls the strait to the recycler view. The title is hidden, I need to scroll up to see it.

Any ideas on what causes this? I do not want to use the type in my adapter if I can avoid it.

+19
source share
3 answers

Harshit Android recyclerview

. scrollView.

android:descendantFocusability="blocksDescendants"

.

+52

. RecyclerView. RecyclerView RecyclerView, Android TV.

23.4.0 24.0.0, . , Activity, , RecyclerView , RecyclerView , .

android:descendantFocusability="blocksDescendants" .

, . RecyclerView a FrameLayout. android:focusableInTouchMode="true" FrameLayout, .

, setFocusable(false) / RecyclerView s. .

, AOSP .

+14

setFocusableInTouchMode=true ( LinearLayout) NestedScrollView

+1

All Articles