3
votes

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
I don't get why you have a NestedScrollView wrapping your ViewPager? Since you have ScrollView on each view I don't think that's needed. And also would be nice to have some code. - ArbenMaloku
Because my view pager is a part of Activity and activity contains many small different kind of views and I need them to scroll as well along with view pager content - vs.thaakur
found solution? - nicover

3 Answers

0
votes

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

0
votes

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

0
votes

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