3

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>
vs.thaakur
  • 619
  • 3
  • 13
  • 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 Oct 16 '19 at 13:16
  • 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 Oct 16 '19 at 13:29
  • found solution? – nicover Nov 02 '20 at 10:14

3 Answers3

0

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

Tariqul Islam
  • 680
  • 6
  • 14
  • Please share your xml. I want to see actually what you are doing – Tariqul Islam Oct 17 '19 at 04:05
  • shared xml. Please take a look – vs.thaakur Oct 17 '19 at 04:33
  • use root layout as androidx.constraintlayout.widget.ConstraintLayout If we are using androidx.core.widget.NestedScrollView and androidx.viewpager.widget.ViewPager i.e. androidx version of NestedScrollView and ViewPager and your view pager is not. scrolling inside NestedScrollView, Make. the root layout as ConstraintLayout, It will work – Yash Bhardwaj May 27 '20 at 09:06
0

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

d12
  • 53
  • 1
  • 8
0

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

Humxa Moghal
  • 122
  • 11