我想在已包含回收器視圖的屏幕底部添加按鈕欄。當我這樣做時,按鈕欄與回收站視圖的最後一個項目重疊,如果我嘗試點擊按鈕欄,回收站視圖中的項目會被點擊。這裏是我的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包含回收視圖,這裏是它的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>
將硬編碼高度添加到相對佈局會使其對各種屏幕尺寸無響應。該解決方案僅適用於特定實例。 – Jordan
它不必以這種方式進行硬編碼。它只是一個已知的變量。您可以將其設置爲一個維度,操作系統將根據設備配置確定分配哪個值。或者,我想如果你真的想要的話,你可以以編程方式完成上述所有操作。 – jwehrle