Renaud Favier Renaud Favier - 25 days ago 14
Android Question

nested scrollview + recyclerview, strange autoscroll behaviour

In a view pager I have several fragments, one of them uses a nested scrollview with a header and a 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 tag "header" represents a complex layout that I didn't want to post here as it stretches out the code a lot.

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

Any ideas on what causes that ? I don't wanna use a type in my adapter if I can avoid it.

Answer

As Harshit said on 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"

It helped me.

Comments