ScrollView inside ViewPager inside NestedScrollView not scrolling

Viewed 825

I have an activity which contains a Nested ScrollView in it. Inside this NestedScrollView there is a ViewPager. Each Page has a view which contains a ScrollView. This innermost scrollview is not scrolling at all. How can I enable the scrolling behaviour in this innermost ScrollView

This is the xml of Activity

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

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

            <androidx.viewpager.widget.ViewPager
                android:id="@+id/pager"
                android:layout_width="match_parent"
                android:layout_height="300dp" />

            <ImageView
                android:layout_width="400dp"
                android:layout_height="400dp"
                android:layout_marginTop="10dp"
                android:src="@drawable/ic_launcher_background" />

            <ImageView
                android:layout_width="400dp"
                android:layout_height="400dp"
                android:layout_marginTop="10dp"
                android:src="@drawable/ic_launcher_background" />

            <ImageView
                android:layout_width="400dp"
                android:layout_height="400dp"
                android:layout_marginTop="10dp"
                android:src="@drawable/ic_launcher_background" />

            <ImageView
                android:layout_width="400dp"
                android:layout_height="400dp"
                android:layout_marginTop="10dp"
                android:src="@drawable/ic_launcher_background" />
        </LinearLayout>
    </androidx.core.widget.NestedScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>

This is xml of view pager

    <?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:orientation="vertical">
    <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="800dp" />

</androidx.core.widget.NestedScrollView>
3 Answers

Add android:fillViewport="true" in your NestedScrollView. I hope the problem will be solved

The scrollview will only scroll if there is content inside and it takes up all the width in the view. Then you will be able to scroll

It will be much easier if you add xml file here Also, Try to add Scroll View in Activity and Nested Scroll View in the Views hold by viewPager Also try to add

fillViewPorty = true

in your top scroll view

Related