【问题标题】:FrameLayout overflows Window in CoordinatorLayoutFrameLayout 溢出 CoordinatorLayout 中的窗口
【发布时间】:2020-09-18 19:21:27
【问题描述】:

我想为scrolling_view_behaviour 实现FrameLayouttoolbar。 但是当我将FrameLayoutlayout_height设置为match_parent时,如下图所示溢出:

这是我的布局文件:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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.NewsActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        >

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            style="@style/Widget.AppCompat.Toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:titleTextColor="#fff" />

    </com.google.android.material.appbar.AppBarLayout>


    <FrameLayout
        android:id="@+id/flFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"


        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:layout_insetEdge="start">

        <fragment
            android:id="@+id/navHostFragment"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:defaultNavHost="true"

            app:navGraph="@navigation/news_nav_graph" />

    </FrameLayout>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNavigationView"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:layout_gravity="bottom"
        android:background="#fff"
        app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
        app:layout_insetEdge="bottom"
        app:menu="@menu/bottom_navigation_menu" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

如果这个问题是重复的或愚蠢的,我很抱歉,我找不到任何可以解决我的问题的东西。提前致谢

【问题讨论】:

    标签: android android-coordinatorlayout android-framelayout


    【解决方案1】:

    您可以删除引用ConstraintLayout 的属性,因为您在这里没有使用一个。还有FrameLayout。在Fragment 的底部添加边距将正确设置它。

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        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">
    
        <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/appBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar">
    
            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                style="@style/Widget.AppCompat.Toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/colorPrimary"
                app:layout_scrollFlags="scroll|enterAlways"
                app:titleTextColor="#fff" />
    
        </com.google.android.material.appbar.AppBarLayout>
    
        <fragment
            android:id="@+id/navHostFragment"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="112dp"
            app:defaultNavHost="true"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            app:navGraph="@navigation/news_nav_graph"
            tools:ignore="FragmentTagUsage" />
    
        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottomNavigationView"
            android:layout_width="match_parent"
            android:layout_height="56dp"
            android:layout_gravity="bottom"
            android:background="#fff"
            app:menu="@menu/bottom_navigation_menu" />
    
    </androidx.coordinatorlayout.widget.CoordinatorLayout>
    

    如你所见,我已经添加了

    android:layout_marginBottom="112dp"
    

    但是如果你添加56dp,它会将底部56dp布局放在BottomNavigationView后面。为了避免在其他布局中的内部子片段,只需向其添加更多 56dp。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-17
      • 1970-01-01
      • 2021-03-07
      • 2014-10-28
      • 1970-01-01
      • 1970-01-01
      • 2016-05-06
      相关资源
      最近更新 更多