BottomNavigationView与最后一项重叠

时间:2017-03-03 06:31:21

标签: android android-layout

我的XML布局如下:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinatorLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <!-- AppBar Layout   -->
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="fill_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >
            <Button
                android:id="@+id/filter_location"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                style="?android:attr/borderlessButtonStyle"
                android:drawableRight="@drawable/ic_filter_list_white_24dp"
                android:layout_gravity="right"
                />
        </android.support.v7.widget.Toolbar>
        <!-- Tab Layout for creating tabs -->
        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    </android.support.design.widget.AppBarLayout>
    <!-- Helps handing the Fragments for each Tab -->
    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/float_search"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginBottom="70dp"
        android:src="@android:drawable/ic_menu_search" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@color/colorPrimary"
        app:itemBackground="@color/colorPrimary"
        app:itemIconTint="@color/windowBackground"
        app:itemTextColor="@color/windowBackground"
        app:menu="@menu/bottom_navigation_main" />
</android.support.design.widget.CoordinatorLayout>

BottomNavigationView与内容中的最后一项重叠。我该怎么解决这个问题?如何在BottomNavigation栏上方生成最后一项?我尝试在里面添加线性布局,但仍然无法正常工作。

6 个答案:

答案 0 :(得分:1)

android:layout_gravity="bottom"移除android.support.design.widget.BottomNavigationView并添加以下内容

app:layout_anchor="@+id/viewPager"
app:layout_anchorGravity="bottom"
android.support.design.widget.BottomNavigationView

中的

答案 1 :(得分:0)

将xml替换为以下xml:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinatorLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <!-- AppBar Layout   -->
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="fill_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

            <Button
                android:id="@+id/filter_location"
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:drawableRight="@drawable/border" />
        </android.support.v7.widget.Toolbar>
        <!-- Tab Layout for creating tabs -->
        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    </android.support.design.widget.AppBarLayout>
    <!-- Helps handing the Fragments for each Tab -->
    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="fill_parent"
        android:layout_height="354dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/float_search"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginBottom="70dp"
        android:src="@android:drawable/ic_menu_search" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@color/colorPrimary"
        app:itemBackground="@color/colorPrimary"
        app:itemIconTint="@color/colorAccent"
        app:itemTextColor="@color/colorPrimaryDark" />
</android.support.design.widget.CoordinatorLayout>

答案 2 :(得分:0)

尝试将其置于相对布局中,并在视图寻呼机中使用以下属性。

@Override
    public void onClick(View view) {

        //add event for each date and show it{timing}
        if (view.getId() == R.id.calendar_day_gridcell) {

           for(int i = 0; i <itemsDetails.size(); i++) {
                listItems = itemsDetails.get(i);
                if(listItems.getPresentDate().equals(day)){
                    inTime = "In Time : " + listItems.getAttTime();
                    clickedDate = "Date : " + listItems.getAttDate();
                    outTime = "Out Time : " + listItems.getAtt_OutTime();
                    attendanceType = "Type : " + listItems.getAttType();
                }
            }
        }
    }

答案 3 :(得分:0)

使用此xml

<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/coordinatorLayout"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">

<!-- AppBar Layout   -->
<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="fill_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >
        <Button
            android:id="@+id/filter_location"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="?android:attr/borderlessButtonStyle"
            android:drawableRight="@drawable/ic_filter_list_white_24dp"
            android:layout_gravity="right"
            />
    </android.support.v7.widget.Toolbar>
    <!-- Tab Layout for creating tabs -->
    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<!-- Helps handing the Fragments for each Tab -->
<android.support.v4.view.ViewPager
    android:id="@+id/viewPager"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/float_search"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginBottom="40dp"
    android:src="@android:drawable/ic_menu_search" />

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

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@color/colorPrimary"
        app:itemBackground="@color/colorPrimary"
        app:menu="@menu/bottom_navigation_main" />

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

</LinearLayout>

答案 4 :(得分:0)

尝试添加此

app:layout_insetEdge="bottom"
BottomNavigationView

中的

答案 5 :(得分:0)

将此行添加到协调器布局中

android:layout_marginBottom =“?attr / actionBarSize”

它将起作用