【发布时间】:2020-09-17 05:10:30
【问题描述】:
我有 NestedScrollView 包含 CardView、TabLayout 和 ViewPager。如果我指定 android:layout_height match_parent 或 wrap_content (只有选项卡名称可见),ViewPager 不会在选项卡上显示内容。它仅在我指定 dp 中的值时才有效
我的 XML 布局如下。
<androidx.core.widget.NestedScrollView
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_marginTop="10dp"
android:id="@+id/DescriptionTv"
android:textStyle="bold"
android:text="Post description"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<com.google.android.material.tabs.TabLayout
app:tabGravity="fill"
android:id="@+id/TabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/Viewpager"
android:layout_width="match_parent"
android:layout_height="500dp"/> // I want to avoid specifying values but not working
</LinearLayout>
</androidx.core.widget.NestedScrollView>
如何避免在数字中指定 android:layout_height 以使 ViewPager 将其与屏幕匹配为 Normal TabLayout?请帮忙
我尝试在 ViewPager 中添加我的 TabLayout 但不起作用(两者都变得不可见)
【问题讨论】:
标签: android android-viewpager android-tablayout android-coordinatorlayout android-nestedscrollview