ViewPager2 not showing in page

79 Views Asked by At

I want to show cardview in the marked area on the screen with ViewPager2. Where might the problem be? My code will pull data from Firestore and display it on the screen.

Output:

enter image description here

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <ScrollView...>

        <LinearLayout...>
         ...
            <androidx.viewpager2.widget.ViewPager2
                android:id="@+id/fragmentTestPage_viewpager"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_constraintBottom_toBottomOf="@+id/fragmentLessonContent_llGroup"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
         ...
        </LinearLayout>

    </ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
2

There are 2 best solutions below

0
Hezy Ziv On

not sure why its not showing, but try to avoid nesting ViewPager2 inside ScrollView. Using a ViewPager2 inside a ScrollView can lead to touch event conflicts since both can respond to vertical swipe gestures.

further you've set the height of ViewPager2 to wrap_content, it might not be able to determine its height properly, especially if the content is dynamic or loaded asynchronously from Firestore. try to set a fixed height or calculate the height dynamically

debug and make sure that you get the data in your adapter

0
Dayakargoud Bandari On

Add fillviewport attribute to scrollview.

android:fillViewport="true"