Viewpager Inside a Scrollview Does Not Scroll Correclty

ViewPager inside a ScrollView does not scroll correclty

Further reading has revealed that there are issues with scrolling components inside scrolling components.

One solution is to 'disable' the vertical scrolling of the ScrollView on the area of the contained scrollable component, in my case a ViewPager.

The code for this solution is detailed here (and its simply brilliant!)

ScrollView doesn't scroll in a ViewPager

Rty this

In your ViewPager

 <androidx.viewpager.widget.ViewPager
android:id="@+id/userInfoViewPager"
android:layout_width="match_parent"
android:layout_height="0dp" // <- ****
app:layout_constraintBottom_toBottomOf="parent" // <- ****
app:layout_constraintTop_toBottomOf="@id/tablayout"
/>

Then, in fragment xml

<ScrollView
....
android:layout_width="match_parent"
android:layout_height="match_parent" // <- ****
>

<androidx.constraintlayout.widget.ConstraintLayout
android:padding="40dp"
android:id="@+id/userInfoContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" // <- ****
>

viewpager inside scrollview makes fragment not displayed when it should

@AlvaroSantisteban Happy I could help. Struggled with this myself too. It all goes down to understanding how layouts work, more specifically understanding wrap_content and match_parent.
So here's the original solution:

Your ViewPager should have a fixed height, considering it's inside a ScrollView.



Related Topics



Leave a reply



Submit