如何在活动中包括底部导航视图布局,使其显示在listview项下方?

时间:2018-08-18 06:58:09

标签: android android-layout listview android-relativelayout

我有一个版式,顶部有一个搜索栏,一个列表视图,然后是一个底部导航视图。问题是,列表视图的最后一项隐藏在底部导航视图的后面。

这是布局的代码:

    <?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"
    android:background="@color/white">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:id="@+id/rel1"
       >


        <RelativeLayout
            android:id="@+id/relLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <include layout="@layout/snippet_searchbar" />
        </RelativeLayout>


        <ListView
            android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/relLayout1"
            android:scrollbars="vertical">

        </ListView>




        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/relLayout1" />


    </RelativeLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_group"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_gravity="bottom|end"
        android:layout_marginBottom="27dp"
        android:layout_marginEnd="27dp"
        android:src="@drawable/ic_next" />

    <include layout="@layout/layout_bottom_navigation_view"

     />
</RelativeLayout>

对于底部导航视图:

<merge xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true">

        <com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/bottomNavViewBar"
            android:background="@drawable/white_grey_border_bottom"
            app:menu="@menu/bottom_navigation_menu"
            app:itemIconTint="@color/secondaryLightColor"
            >


        </com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx>



    </RelativeLayout>



</merge>

如何解决此问题,以使底部导航视图出现在列表视图的下方,而带有滚动条的列表视图的最后一项显示在底部导航的上方,即使滚动到底部也是如此。

2 个答案:

答案 0 :(得分:0)

使用高度来定义listView而不是使用wrap_content或match_parent,这样底部内容和listView行将不会相互覆盖

答案 1 :(得分:0)

为包含布局提供ID,并在底部导航视图上方设置相对布局:

<?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"
    android:background="@color/white">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_above="@id/bottom_nav_view"
        android:id="@+id/rel1" >


        <RelativeLayout
            android:id="@+id/relLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <include layout="@layout/snippet_searchbar" />
        </RelativeLayout>

        <ListView
            android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/relLayout1"
            android:scrollbars="vertical">

        </ListView>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/relLayout1" />


    </RelativeLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_group"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_gravity="bottom|end"
        android:layout_marginBottom="27dp"
        android:layout_marginEnd="27dp"
        android:src="@drawable/ic_next" />

    <include layout="@layout/layout_bottom_navigation_view"
        android:id="@+id/bottom_nav_view"
         />
</RelativeLayout>