代码之家  ›  专栏  ›  技术社区  ›  sir-haver

带制表符的视图寻呼机布局超出屏幕界限

  •  0
  • sir-haver  · 技术社区  · 5 年前

    我使用了一个选项卡布局,在一个视图页面下显示所选片段的内容。

    在布局的顶部是选项卡布局,在视图页面的下面。问题是:视图寻呼机会占用整个屏幕的高度,因此(因为它被限制在导航选项卡上),它的高度会超出屏幕,如下所示:

    enter image description here

    我的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"/>
    

    有没有办法将视图寻呼机限制在导航选项卡的顶部,并强制其高度保持在屏幕范围内?这看起来可能无关紧要,但它会导致片段中的小部件出现在屏幕之外

    1 回复  |  直到 5 年前
        1
  •  1
  •   Ethan Choi    5 年前

    视图寻呼机占据了整个屏幕的高度

    ViewPager onMeasure 功能, 包装内容 计算为容器大小(在本例中, 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" />
    
        2
  •  1
  •   Chaitali Jain    5 年前

    在这里你的视图寻呼机是采取全屏的高度。请使用 下面的代码显示选项卡下面的视图寻呼机:

    <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" />