简体   繁体   English

框架布局位于底部导航栏的后面吗?

[英]Frame Layout is Going Behind the Bottom Navigation Bar?

I have a frame layout in the activity. 我在活动中有框架布局。 I have put an action bar and bottom navigation bar in the activity, but the problem is the frame layout is going behind the bottom navigation bar, and it's also not scrolling. 我在活动中放置了操作栏和底部导航栏,但是问题是框架布局在底部导航栏的后面,并且它也不滚动。 I want the frame layout to always remain above the bottom navigation bar. 我希望框架布局始终保持在底部导航栏上方。

I have tried giving the bottom navigation drawer a fixed height of "56dp", and layout_margin Bottom="56dp". 我尝试将底部导航抽屉的固定高度设置为“ 56dp”,然后将layout_margin Bottom =“ 56dp”设置为固定高度。 It works fine, But I don't think it is a good solution, because in some cases, I want to hide the bottom navigation bar. 它工作正常,但是我认为这不是一个好的解决方案,因为在某些情况下,我想隐藏底部的导航栏。

<?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>

// Bottom Navigation Bar Code: //底部导航条形码:

<?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>

I want the frame layout to remain below the toolbar and above the bottom navigation bar. 我希望框架布局保持在工具栏下方和底部导航栏上方。

But what happens, is the frame layout is below the toolbar, but the frame layout is behind the bottom navigation bar. 但是发生的是,框架布局在工具栏下方,但是框架布局在底部导航栏的后面。

My approach would be to wrap the wrap the bottom navigation Layout you included in a LinearLayout and then wrap the FrameLayout and the new layout containing the bottom navigation bar in a relative layout then position the frame layout above the bottom navigation bar layout such that: 我的方法是包装包裹在LinearLayout中的底部导航布局,然后将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>

Try this: 尝试这个:

          <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" />

try to place this include tag above Framelayout like 尝试将这个include标签放在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" />

sorry for late answer.. Can you try this ? 对不起,我晚回答了。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM