【问题标题】:FrameLayout doesn't fit the screenFrameLayout 不适合屏幕
【发布时间】:2020-05-21 14:50:29
【问题描述】:

所以我正在开发一个使用 FrameLayout 作为片段容器的应用程序,其内容取决于底部导航器上的选定项目。我的问题是,出于某种原因,我无法让 FrameLayout 适合整个屏幕,所以每当我运行应用程序时,我总是在片段顶部有一个空白区域。我试图改变长度,改变边距,但似乎没有任何效果。我错过了什么?代码如下:

<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="?attr/actionBarSize">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="0dp"
        android:layout_marginEnd="0dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/bottom_nav_menu" />

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toTopOf="@id/nav_view"
        app:layout_constraintHorizontal_bias="0.038"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.094" />

</androidx.constraintlayout.widget.ConstraintLayout>

结果如下:

提前致谢!

【问题讨论】:

    标签: android xml android-studio android-framelayout


    【解决方案1】:

    您的ConstraintLayout 有顶部填充物,因此孩子们永远无法到达顶部。

    如果您想要全屏,请将其从 ConstraintLayout 中删除

    android:paddingTop="?attr/actionBarSize
    

    【讨论】:

    • 非常感谢!像魅力一样工作!
    猜你喜欢
    • 2016-05-25
    • 1970-01-01
    • 1970-01-01
    • 2018-02-11
    • 1970-01-01
    • 1970-01-01
    • 2016-04-22
    • 1970-01-01
    • 2016-09-20
    相关资源
    最近更新 更多