底部栏跌至导航栏后面的低处

时间:2018-07-09 05:31:17

标签: android android-layout

底部导航隐藏在设备按钮的后面,请参见下图:

enter image description here

我不能使用任何scrollview视图或任何其他视图。

请参阅以下我的活动代码:

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:openDrawer="start"
    android:background="@color/offwhite"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/nav_menu"
        />


    <RelativeLayout
        android:layout_below="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <FrameLayout
            android:id="@+id/nav_Frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_above="@+id/bottom_navigation"
            >
        </FrameLayout>

        <LinearLayout
            android:id="@+id/bottom_navigation"
            android:layout_width="match_parent"
            android:layout_height="@dimen/_40sdp"
            android:background="@color/white"
            android:layout_alignParentBottom="true"
            >

            <ImageView
                android:id="@+id/iv_home"
                android:layout_width="@dimen/_20sdp"
                android:layout_height="@dimen/_20sdp"
                android:src="@drawable/ic_myaccount"
                android:tint="@color/light_gray"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"
                />

            <ImageView
                android:id="@+id/iv_notification"
                android:layout_width="@dimen/_20sdp"
                android:layout_height="@dimen/_20sdp"
                android:src="@drawable/ic_myaccount"
                android:tint="@color/light_gray"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"
                />

            <ImageView
                android:id="@+id/iv_add"
                android:layout_width="@dimen/_20sdp"
                android:layout_height="@dimen/_20sdp"
                android:src="@drawable/ic_myaccount"
                android:tint="@color/light_gray"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"
                />

            <ImageView
                android:id="@+id/iv_massage"
                android:layout_width="@dimen/_20sdp"
                android:layout_height="@dimen/_20sdp"
                android:src="@drawable/ic_myaccount"
                android:tint="@color/light_gray"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"
                />

            <ImageView
                android:id="@+id/iv_account"
                android:layout_width="@dimen/_20sdp"
                android:layout_height="@dimen/_20sdp"
                android:src="@drawable/ic_myaccount"
                android:tint="@color/light_gray"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"
                />

        </LinearLayout>


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

style.xml代码:

 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

6 个答案:

答案 0 :(得分:1)

分隔您的布局

content_layout.xml

<RelativeLayout 
 xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_below="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
    android:id="@+id/nav_Frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_above="@+id/bottom_navigation"
    >
</FrameLayout>

<LinearLayout
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="@dimen/_40sdp"
    android:background="@color/white"
    android:layout_alignParentBottom="true"
    >

    <ImageView
        android:id="@+id/iv_home"
        android:layout_width="@dimen/_20sdp"
        android:layout_height="@dimen/_20sdp"
        android:src="@drawable/ic_myaccount"
        android:tint="@color/light_gray"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        />

    <ImageView
        android:id="@+id/iv_notification"
        android:layout_width="@dimen/_20sdp"
        android:layout_height="@dimen/_20sdp"
        android:src="@drawable/ic_myaccount"
        android:tint="@color/light_gray"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        />

    <ImageView
        android:id="@+id/iv_add"
        android:layout_width="@dimen/_20sdp"
        android:layout_height="@dimen/_20sdp"
        android:src="@drawable/ic_myaccount"
        android:tint="@color/light_gray"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        />

    <ImageView
        android:id="@+id/iv_massage"
        android:layout_width="@dimen/_20sdp"
        android:layout_height="@dimen/_20sdp"
        android:src="@drawable/ic_myaccount"
        android:tint="@color/light_gray"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        />

    <ImageView
        android:id="@+id/iv_account"
        android:layout_width="@dimen/_20sdp"
        android:layout_height="@dimen/_20sdp"
        android:src="@drawable/ic_myaccount"
        android:tint="@color/light_gray"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        />

</LinearLayout>

drawer_activity.xml

<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start"
android:background="#E2DEDE"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">

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

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    />

答案 1 :(得分:0)

尝试一下

将此添加到您的应用主题中:

<item name="android:windowTranslucentNavigation">false</item>

答案 2 :(得分:0)

从扩展您的底部导航

public class BottomNavigationBehavior extends CoordinatorLayout.Behavior<BottomNavigationView> {

public BottomNavigationBehavior() {
    super();
}

public BottomNavigationBehavior(Context context, AttributeSet attrs) {
    super(context, attrs);
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, BottomNavigationView child, View dependency) {
    boolean dependsOn = dependency instanceof FrameLayout;
    return dependsOn;
}
@Override
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, BottomNavigationView child, View directTargetChild, View target, int nestedScrollAxes) {
    return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL;
}

@Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, BottomNavigationView child, View target, int dx, int dy, int[] consumed) {
    if (dy < 0) {
        showBottomNavigationView(child);
    } else if (dy > 0) {
        hideBottomNavigationView(child);
    }
}

private void hideBottomNavigationView(BottomNavigationView view) {
    view.animate().translationY(view.getHeight());
}

private void showBottomNavigationView(BottomNavigationView view) {
    view.animate().translationY(0);
}

}

答案 3 :(得分:0)

我对此进行了搜索,最后我明白了为什么该底部导航显示在底部栏下

我在Java类中的Flag下方删除。

getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

我添加了此标志以将ActionbarStatusbar混合使用。

因此,我只删除了该标志,它看起来很完美。 :)

答案 4 :(得分:0)

尝试一下

将此添加到您的活动xml中: 根DrawerLayout:

    android:fitsSystemWindows="true"

答案 5 :(得分:0)

enter image description here

要在任何活动中实现这一目标

  1. 添加样式:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:windowBackground">@android:color/white</item>
</style>
  1. 将CoordinatorLayout用作活动的XML的根布局

  2. oncreate()方法中,在使用setcontentview之前

  

window.decorView.systemUiVisibility =   View.SYSTEM_UI_FLAG_LAYOUT_STABLE或   View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN