Android - 如何在ScrollView中填充LinearLayout

Android - How to fill LinearLayout in ScrollView

ScrollView中有LinearLayout

我想用 ViewPager 填充 LinearLayout,

但是ViewPager的高度是0。

LinearLayout的tabLayout下面的区域必须用ViewPager填充

如果我将 ViewPager 的高度设置为特定的 dp,

它显​​示蓝色。

请帮忙

(红色:ScrollView,蓝色:ViewPager)

MainFragment.xml

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:background="@color/red"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:orientation="vertical">
        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:layout_weight="0">
            <Button
                android:id="@+id/ATabButton"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:text="A"
                android:textSize="18sp"
                android:textStyle="bold"
                android:background="@drawable/shape_tab_button_clicked"
                android:stateListAnimator="@null"
                app:layout_constraintWidth_percent="0.5"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toStartOf="@id/reviewTabButton">
            </Button>
            <Button
                android:id="@+id/BTabButton"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:text="B"
                android:background="@drawable/shape_tab_button_unclicked"
                android:stateListAnimator="@null"
                app:layout_constraintWidth_percent="0.5"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintStart_toEndOf="@id/menuTabButton"
                app:layout_constraintEnd_toEndOf="parent">
            </Button>
        </androidx.constraintlayout.widget.ConstraintLayout>
        <androidx.viewpager.widget.ViewPager
            android:id="@+id/contentsViewPager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@color/blue"/>
    </LinearLayout>

</ScrollView>

在 ScrollView 中添加填充视口

android:fillViewport="true"