Android 按钮栏与回收器视图重叠问题

Android 按钮栏与回收器视图重叠问题,android,xml,material-design,Android,Xml,Material Design,我正在尝试在屏幕底部添加一个按钮栏,其中已经包含一个回收器视图。当我这样做时,按钮栏与recycler视图的最后一个项目重叠,如果我尝试单击按钮栏,则会单击recycler视图中它下面的项目。以下是我的xml: <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/r

我正在尝试在屏幕底部添加一个按钮栏,其中已经包含一个回收器视图。当我这样做时,按钮栏与recycler视图的最后一个项目重叠,如果我尝试单击按钮栏,则会单击recycler视图中它下面的项目。以下是我的xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:fitsSystemWindows="true"
tools:context="com.example.owaisnizami.navigation.MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

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




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

    <LinearLayout
    android:id="@+id/buttonBar"
    android:layout_width="match_parent"


    android:layout_height="wrap_content"

    android:layout_alignParentBottom="true"
    style="@android:style/ButtonBar"
    android:background="#F44336"
    android:layout_gravity="bottom|end">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="30sp"
        android:layout_gravity="center"
        android:text="Advertisements Here"
        android:textColor="#FFFFFF"/>
</LinearLayout>


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

content_main包含recycler视图,以下是其xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main"
tools:context=".MainActivity">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"/>
</RelativeLayout>

将您的按钮栏布局移动到主内容中,如下所示

<RelativeLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main"
tools:context=".MainActivity">

<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/buttonBar"
android:scrollbars="vertical"/>

 <LinearLayout
android:id="@+id/buttonBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
style="@android:style/ButtonBar"
android:background="#F44336"
>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="30sp"
    android:layout_gravity="center"
    android:text="Advertisements Here"
    android:textColor="#FFFFFF"/>
 </LinearLayout>
</RelativeLayout>


通过这种方式,您可以确保recyclerView在按钮栏布局之前结束

我已经并且现在已经解决了这个问题,解决方案并不像我想象的那么复杂

在保存RecyclerView的content_main布局中,设置

android:layout_marginBottom="<height-of-your-button-bar>"
android:layout_marginBottom=“”
为保存您的RecyclerView而不是您的RecyclerView本身的RelativeLayout设置此选项

现在,当您滚动到列表底部时,它将继续滚动,以便最后一项不会被按钮栏隐藏

查看布局,您可能需要确定按钮栏的高度,以便相应地设置此边距

希望这有帮助


完全公开,我将此解决方案与NestedScrollView而不是RelativeLayout一起使用,尽管我不知道为什么它不起作用-而且,如果切换到NestedScrollView,您的CollapsableToolbar将能够折叠。

我尝试过!没有解决问题@Ragesh Ramesh你的碎片容器装的是什么?你在里面装碎片吗。如果是这样的话,也将安卓:layout_over=“@+id/buttonBar”添加到片段布局中。为什么有一个片段容器和RecyclerView相互重叠?如果你问的是框架布局,它是无用的,我已经删除了它!我以前使用过片段,但现在没有在这里使用!我也编辑了上面的代码@Ragesh RameshI改变了我的答案。现在试试这个,我试过了,但还是不行@Ragesh Rameshading将硬编码高度设置为相对布局将使其对各种屏幕尺寸无响应。该解决方案仅适用于特定实例,不必以这种方式硬编码。它必须是一个已知的变量。您可以将其设置为维度,操作系统将根据设备配置确定要分配的值。或者,我想如果你真的想做的话,你可以通过编程来完成上面的所有工作。