我正在尝试在已经包含回收站 View 的屏幕底部添加一个按钮栏。当我这样做时,按钮栏与回收器 View 的最后一项重叠,如果我尝试单击按钮栏,回收器 View 中它下面的项目将被单击。这是我的 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 包含回收器 View ,这是它的 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>
最佳答案
我已经解决了这个问题,而且解决方案并不像我想的那么复杂。
在包含 RecyclerView 的 content_main 布局中,设置
android:layout_marginBottom="<height-of-your-button-bar>"
为保存您的 RecyclerView 的 RelativeLayout 设置此项,不是您的 RecyclerView 本身。
现在,当您滚动到列表底部时,它会继续滚动,这样最后一项就不会被按钮栏隐藏。
查看您的布局,您可能需要确定按钮栏的高度,以便相应地设置此边距。
希望这对您有所帮助。
完全公开,我将此解决方案与 NestedScrollView 而不是 RelativeLayout 一起使用,但不知道为什么它不起作用 - 此外,如果您切换到 NestedScrollView,您的 CollapsableToolbar 将能够折叠。
关于android - 按钮栏与回收站 View 问题重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35911502/