NestedScrollView could not scroll using match_parent height child

I implement a NonSwipeablePpager with a snippet that has a NestedScrollView like this, I expect scrollview to scroll up and show 2 text views:

<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <include android:id="@+id/header" android:layout_width="match_parent" android:layout_height="match_parent" layout="@layout/header" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="16dp" android:src="@drawable/ic_up" /> </RelativeLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Text 1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Text 2" /> </LinearLayout> </android.support.v4.widget.NestedScrollView> 

But he could not scroll, I tried many ways, but still have not received any solution

+6
source share
3 answers
 <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> 

This line output should have android:layout_height="wrap_content" .

The reason for this is that if the child of the scrollview is the same size as the scrollview itself (both match_parent for height), this means that there is nothing to scroll because they are the same size and the scrollview will only look like a screen.

If linearlayout has wrap_content height, then the height is not related to the height of the screen, and scrollview will be able to scroll through it.

Just remember that scrollview can have only one direct child, and this child requires android:layout_height="wrap_content"

+29
source

In my case, app:layout_behavior="@string/appbar_scrolling_view_behavior" this only works if some kind of face problem is facing the problem and can also solve your problem. you should also add android:fillViewport="true" , but without this my code works.

  <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" xmlns:app="http://schemas.android.com/apk/res-auto" android:background="@drawable/subscription_background" app:layout_behavior="@string/appbar_scrolling_view_behavior"> 
+1
source

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

All Articles