【问题标题】:Android - How to fill LinearLayout in ScrollViewAndroid - 如何在 ScrollView 中填充 LinearLayout
【发布时间】:2020-11-06 00:27:21
【问题描述】:

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>

【问题讨论】:

    标签: android android-viewpager scrollview android-linearlayout


    【解决方案1】:

    在 ScrollView 中添加填充视口

    android:fillViewport="true"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-15
      • 1970-01-01
      • 1970-01-01
      • 2017-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多