框架布局(Frame Layout)被覆盖在底部导航栏后面了?

3
我在activity中有一个框架布局。我已经在activity中放置了一个操作栏和底部导航栏,但问题是框架布局会被底部导航栏遮挡,并且也无法滚动。我希望框架布局始终保持在底部导航栏上方。
我尝试给底部导航抽屉设置固定高度为"56dp",并设置layout_margin Bottom="56dp"。它可以正常工作,但我认为这不是一个好的解决方案,因为在某些情况下,我想隐藏底部导航栏。
<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 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"
        android:background="#fafafa"
        android:orientation="vertical"
        tools:context=".Activities.Dashboard">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="@dimen/abc_action_bar_default_height_material"
            android:background="#ff2729c3"
            app:layout_scrollFlags="scroll|enterAlways"
            app:navigationIcon="@drawable/navigation_icon"
            app:theme="@style/AppTheme.Toolbar">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageView
                    android:layout_width="32dp"
                    android:layout_height="32dp"
                    android:src="@mipmap/app_logo" />


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginStart="38dp"
                    android:layout_marginTop="4dp"
                    android:fontFamily="cursive"
                    android:text="LootBox"
                    android:textColor="@color/white"
                    android:textSize="22sp"
                    android:textStyle="bold" />

                <ImageView
                    android:layout_width="24dp"
                    android:layout_height="24dp"
                    android:layout_alignParentTop="true"
                    android:layout_alignParentEnd="true"
                    android:layout_marginTop="4dp"
                    android:layout_marginEnd="56dp"
                    android:src="@drawable/pin_posts" />

                <include
                    layout="@layout/notification_icon_count_badge"
                    android:layout_width="24dp"
                    android:layout_height="24dp"
                    android:layout_alignParentTop="true"
                    android:layout_alignParentEnd="true"
                    android:layout_marginTop="4dp"
                    android:layout_marginRight="16dp" />

            </RelativeLayout>

        </android.support.v7.widget.Toolbar>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#ff9800" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">


            <android.support.v4.widget.DrawerLayout
                android:id="@+id/myDrawer"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

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


                <include layout="@layout/bottom_nav" />

                <android.support.design.widget.NavigationView
                    android:id="@+id/nav"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_gravity="start"
                    android:background="@color/colorPrimary"
                    app:headerLayout="@layout/nav_header"
                    app:itemBackground="@drawable/drawer_item_bg"
                    app:itemIconTint="@color/white"
                    app:itemTextColor="@color/white"
                    app:menu="@menu/my_menu">

                </android.support.design.widget.NavigationView>

            </android.support.v4.widget.DrawerLayout>

        </RelativeLayout>

    </LinearLayout>

// 底部导航栏代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_above="@+id/bottomNavi"
        android:background="#ff9800"></View>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottomNavi"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom"
        android:background="@color/colorPrimary"
        app:itemIconTint="@color/botto_nav_color"
        app:itemTextColor="@color/botto_nav_color"
        app:menu="@menu/bottom_nav_menu"/>

</RelativeLayout>

我希望框架布局仍然位于工具栏下方和底部导航栏上方。

但实际情况是,框架布局位于工具栏下方,但在底部导航栏后面。


你可以考虑将独立的布局代码移动到主布局中,而不是将其包含在内。 - karan
请将布局位置更改为首先是导航栏,其次是框架布局。 - Ashwani kumar
fragment_container_dashboard.bringToFront(); 或许这会对你有所帮助。 - vishva kapadia
4个回答

1

试试这个:

          <FrameLayout
                android:id="@+id/fragment_container_dashboard"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="56dp"
                android:layout_above="@+id/nav" />


          <include android:id="@+id/nav" 
                layout="@layout/bottom_nav" />

0

抱歉回复晚了.. 你可以试试这个吗?

<include        
    android:layout_alignParentBottom="true"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    layout="@layout/bottom_nav" />

0
我的方法是将您包含在LinearLayout中的底部导航布局进行包装,然后将FrameLayout和包含底部导航栏的新布局包装在RelativeLayout中,然后将FrameLayout定位在底部导航栏布局上方,使其如下所示:
   <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <FrameLayout
            android:id="@+id/fragment_container_dashboard"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="56dp" 
            android:layout_above="@id/bnve"/>

        <LinearLayout
            android:id="@+id/bnve"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <include layout="@layout/bottom_nav" />
        </LinearLayout>
    </RelativeLayout>

那么我应该把我的抽屉布局放在哪里? - Saransh Agarwal
抽屉布局保持不变,只需将框架布局和底部栏包装在一个相对布局中,就像我所做的那样,并将该相对布局放置在您的抽屉布局下方。 - Asendo

0

尝试将这个包含标签放在Framelayout上方,如下所示:

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">


            <android.support.v4.widget.DrawerLayout
                android:id="@+id/myDrawer"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

              <include layout="@layout/bottom_nav" />

                <FrameLayout
                    android:id="@+id/fragment_container_dashboard"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginBottom="56dp" />

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接