【发布时间】: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