[英]View pager with tabs layout is out of screen bounds
我正在使用選項卡布局並在視圖分頁器下方顯示所選片段的內容。
在布局頂部有選項卡布局,在視圖尋呼機下方。 問題是:視圖分頁器采用全屏的高度,因此(因為它被限制在導航選項卡上),它的高度像這樣走出屏幕:
我的xml:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MeetActivity">
<com.google.android.material.tabs.TabLayout
android:id="@+id/navigationTabs"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/navigation_shadow"
app:layout_constraintTop_toTopOf="parent"
app:tabIndicator="@null"
app:tabMinWidth="@dimen/navigation_height"
app:tabRippleColor="@null" />
<!-- // the fragment will be displayed here:-->
<androidx.viewpager.widget.ViewPager
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/navigationTabs"/>
有沒有辦法將視圖尋呼機限制在導航選項卡的頂部並強制其高度保持在屏幕范圍內? 這可能看起來微不足道,但它會導致片段中的小部件出現在屏幕之外
視圖尋呼機占據全屏的高度
在ViewPager
onMeasure
函數中, wrap_content被計算為容器大小(在本例中為ConstaraintLayout
)。
<androidx.viewpager.widget.ViewPager
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/navigationTabs" />
在這里,您的視圖尋呼機占據了全屏的高度。 請使用以下代碼在您的選項卡下方顯示視圖尋呼機:
<androidx.viewpager.widget.ViewPager
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/navigationTabs" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.