【问题标题】:FrameLayout doesn't fit its spaceFrameLayout 不适合其空间
【发布时间】:2018-08-03 18:14:27
【问题描述】:

我是第一次使用 NavigationBar 小部件,我无法将 FrameLayout 设置为不在 NavigationBar 后面。 我已经尝试了所有方法:在 RelativeLayout (NavigationBar 消失) 中进行设置,我在 StackOverflow 周围找到的所有设置,但我没有成功。

这是我的代码:

<?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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="mypackage.myActivity"
    android:background="@color/background_activities">

    <FrameLayout
        android:id="@+id/frame_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true"
        app:layout_constraintTop_toTopOf="parent"
        android:fitsSystemWindows="true"
        >
    </FrameLayout>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@color/color_NavigationBar"
        app:itemIconTint="@color/white"
        app:itemTextColor="@color/white"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation" />

</android.support.constraint.ConstraintLayout>

希望有人能帮助我找出我犯错的地方。 非常感谢

编辑 现在导航栏在点击时开始改变尺寸(看起来整个布局再次“渲染”),现在它卡在这样的位置

【问题讨论】:

    标签: android xml android-fragments fragment


    【解决方案1】:

    试试这个,将框架布局约束设置为完全剪辑到父级,除了底部剪辑到导航的顶部,然后将高度和宽度设置为 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:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="mypackage.myActivity"
        android:background="@color/background_activities">
    
        <FrameLayout
            android:id="@+id/frame_layout"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:animateLayoutChanges="true"
            app:layout_constraintBottom_toTopOf="@+id/navigation"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"></FrameLayout>
    
        <android.support.design.widget.BottomNavigationView
            android:id="@+id/navigation"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:background="@color/color_NavigationBar"
            app:itemIconTint="@color/white"
            app:itemTextColor="@color/white"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:menu="@menu/navigation" />
    
    </android.support.constraint.ConstraintLayout>
    

    【讨论】:

    • 使用您的建议它可以工作,但现在 NavigationBar 在单击时开始“更改高度”,我用图片更新了第一个 psot。你能再帮我一次吗?
    • 我看不到图片:/
    • 尝试将导航高度改为android:layout_height="wrap_content"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-26
    • 2021-03-29
    • 1970-01-01
    • 2017-02-17
    • 1970-01-01
    相关资源
    最近更新 更多