JSONParser
JSONParser

Reputation: 1132

Parent NestedScrollView containing viewpager do not scroll

I have activity which has a nestedscrollview inside which is a view pager view pager has a fragment and fragment has nestedscrollview. Below is the structure:

<LinearLayout>
  <NestedScrollView (Parent)
    android:layout_width="match_parent"
    android:id="@+id/parent_scroll"
    android:layout_height="match_parent"
    android:descendantFocusability="blocksDescendants"
    android:fillViewport="true">
    <LinearLayout << Stuck layout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical">
        <TextView />
      </LinearLayout>
      <cViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    </LinearLayout>
  </NestedScrollView>
</LinearLayout>

The view has a fragment inside . The layout of the fragment is as:

<NestedScrollView (inside fragment, child)
  android:id="@+id/nestedScrollView"
  android:layout_width="match_parent"
  android:descendantFocusability="blocksDescendants"
  android:paddingBottom="40dp"
  android:layout_height="wrap_content"
  android:fillViewport="true"
  android:scrollbars="none"
  app:layoutManager="android.support.v7.widget.LinearLayoutManager">


  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="12dp"
    android:orientation="vertical"/>
</NestedScrollView>

The Problem

When try to scroll the child view (NestedScrollView inside fragment) it get scrolled but parent Nested scroll view inside activity do not get scrolled. I have already implemented coordinator layout but in that there is a issue.On flinging the whole layout gets stuck. But works when scrolling slowly so removed it.

If more code is required let me know.

Upvotes: 1

Views: 759

Answers (1)

Dmytro Ivanov
Dmytro Ivanov

Reputation: 1310

Remove LinearLayout which is parent of your NestedScrollView. Then make this changes to your NestedScrollView:

<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/nestedScrollView"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   app:layout_behavior="@string/appbar_scrolling_view_behavior">

Here is people already talked about this issue.

Upvotes: 0

Related Questions