除了底部导航视图之外,如何使片段的布局具有屏幕高度的高度?

Ser*_*kii 0 xml android

我面临以下问题:我需要制作一个片段,除了底部导航视图外,它的高度与屏幕的高度相同。这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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=".ui.main.MainActivity">

    <FrameLayout
        android:id="@+id/tabs_fragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#111111"
        app:layout_constraintBottom_toTopOf="@id/bottom_nav" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_nav"
        android:layout_width="match_parent"
        android:layout_height="@dimen/bottom_nav_height"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_nav_menu" />


</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

我加android:background="#111111"了看看,fragment的真实高度是多少。可能我认为这app:layout_constraintBottom_toTopOf="@id/bottom_nav"可以帮助我,但不幸的是它没有解决我的问题。那么,我该如何处理呢?

小智 6

如果您希望高度适合您的约束,您需要将 FrameLayout 的 layout_height 设置为 0dp。

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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=".ui.main.MainActivity">

    <FrameLayout
        android:id="@+id/tabs_fragment"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#111111"
        app:layout_constraintBottom_toTopOf="@id/bottom_nav"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_nav"
        android:layout_width="0dp"
        android:layout_height="@dimen/bottom_nav_height"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_nav_menu" />


</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)