I have a Xamarin.Android app in which I am trying to use ViewPager2
. The ViewPager2
is defined in my layout as follows:
<androidx.viewpager2.widget.ViewPager2 android:id="@+id/vpStartScore" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="fill" android:background="@color/DimGray"/>
And the ViewHolder
(s) are created from the following:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:columnCount="1" android:rowCount="2" android:paddingTop="2dp" tools:background="@color/Red" tools:ignore="ContentDescription,HardcodedSize,MissingDimension">
<FrameLayout android:id="@+id/frmBar" android:layout_column="0" android:layout_row="0" android:layout_width="match_parent" android:layout_height="4dp" android:layout_rowWeight="1" android:layout_gravity="center_vertical" android:background="@color/Black"/>
<ImageView android:id="@+id/imgTick" android:layout_column="0" android:layout_row="0" android:layout_width="2dp" android:layout_height="@dimen/TickSizeLarge" android:layout_rowWeight="1" android:layout_gravity="center" android:layout_margin="0dp" android:padding="0dp" android:background="@drawable/tickdrawablelarge"/>
<TextView android:id="@+id/txtValue" android:layout_column="0" android:layout_row="1" android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/InfoMessageTextViewStyle" android:background="@color/Transparent" android:visibility="visible" android:layout_gravity="center_vertical|fill_horizontal" android:layout_margin="0dp" android:padding="0dp" android:textAlignment="center" android:textColor="@color/Black" tools:text="0"/>
</GridLayout>
However, when trying to run the app, I receive the following Exception
:
Java.Lang.IllegalStateException: 'Pages must fill the whole ViewPager2 (use match_parent)'
As you can see, the layout_width
& layout_height
of both my ViewPager2
& root GridLayout
are match_parent
. I don't have a lot of experience with ViewPager2
(or ViewPager
), but I have used RecyclerView
many times in the past. What is the problem? Thanks.