2016-03-10 26 views
0

我想在已包含回收器視圖的屏幕底部添加按鈕欄。當我這樣做時,按鈕欄與回收站視圖的最後一個項目重疊,如果我嘗試點擊按鈕欄,回收站視圖中的項目會被點擊。這裏是我的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> 

回答

2

我已經和hav現在解決了這個問題,解決方案不像我想的那麼複雜。

在保存您的RecyclerView在content_main佈局,設置

android:layout_marginBottom="<height-of-your-button-bar>" 

設置此爲RelativeLayout的持有你的RecyclerView,你RecyclerView本身。

現在,當您滾動到列表底部時,它將繼續滾動,以便最後一項不會被按鈕欄隱藏。

查看您的佈局,您可能需要確定按鈕欄的高度,以便相應地設置此邊距。

希望這會有所幫助。

完全公開,我使用了NestingScrollView而不是RelativeLayout的解決方案,但不知道爲什麼它不起作用 - 另外,如果切換到NestingScrollView,您的CollapsableToolbar將能夠摺疊。

+0

將硬編碼高度添加到相對佈局會使其​​對各種屏幕尺寸無響應。該解決方案僅適用於特定實例。 – Jordan

+1

它不必以這種方式進行硬編碼。它只是一個已知的變量。您可以將其設置爲一個維度,操作系統將根據設備配置確定分配哪個值。或者,我想如果你真的想要的話,你可以以編程方式完成上述所有操作。 – jwehrle

0

移動你的按鈕欄佈局的content_main內,如下

<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在按鈕欄佈局之前結束

+0

我試了一下!沒有解決問題! @Ragesh Ramesh – Jordan

+0

你的碎片容器能容納什麼?你正在加載片段嗎?如果是這樣,請將android:layout_above =「@ + id/buttonBar」添加到片段佈局中。爲什麼有一個片段容器和RecyclerView相互重疊? –

+0

如果您詢問框架佈局,它是無用的,我已經刪除它!我正在使用片段,但現在不在這裏使用它們!我也編輯了上面的代碼! @Ragesh Ramesh – Jordan