【问题标题】:How to include a bottom navigation view layout in an activity so that it appears below the listview items?如何在活动中包含底部导航视图布局,使其显示在列表视图项下方?
【发布时间】:2018-08-18 06:58:08
【问题描述】:

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

这是布局的代码:

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

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

【问题讨论】:

  • 尝试添加一些android:paddingBottom="30dp"
  • 您可以尝试 LinearLayout 而不是 RelativeLayout 并将方向设置为垂直,这样它会自动将您的视图排列在一个下方。

标签: android android-layout listview android-relativelayout


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    给包含布局一个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>
    

    【讨论】:

    • 然后重新开始,因为这是在使用相对布局时将布局置于另一个布局之上的方式
    猜你喜欢
    • 2019-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多