2016-12-21 44 views
0

我有一個recyclerviewbuttonalignParentBottom。視圖看起來很好,除了我的recyclerview的最後一行項目被按鈕阻止,因爲看起來我的recyclerview是「」後面的「按鈕和而不是上方的按鈕。我怎樣才能解決這個問題?設置recyclerview上面alignParentBottom佈局

這裏是我的佈局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white_three" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/orderList" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:layout_width="match_parent"> 
     </android.support.v7.widget.RecyclerView> 

     <TextView 
      android:id="@+id/errorLoadingText" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:textSize="15sp" 
      android:visibility="gone" 
      android:layout_marginTop="120dp" 
      android:gravity="center"/> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/white_three" 
     android:layout_alignParentBottom="true" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/paymentButtonTop" 
      android:layout_width="match_parent" 
      android:layout_height="43dp" 
      android:background="@drawable/button_radius_toggle_confirm" 
      android:layout_marginTop="15dp" 
      android:layout_marginStart="15dp" 
      android:layout_marginEnd="15dp" 
      android:layout_marginBottom="75dp" 
      android:text="@string/prepayment" 
      android:textColor="@color/warm_grey_two" 
      android:enabled="false" 
      android:textSize="17sp" 
      android:gravity="center" /> 

     <TextView 
      android:id="@+id/paymentButton" 
      android:layout_width="match_parent" 
      android:layout_height="43dp" 
      android:background="@drawable/button_radius_toggle_confirm" 
      android:layout_margin="15dp" 
      android:visibility="gone" 
      android:enabled="false" 
      android:textColor="@color/warm_grey_two" 
      android:text="@string/prepayment" 
      android:textSize="17sp" 
      android:gravity="center" /> 

    </LinearLayout> 

</RelativeLayout> 

回答

1

你的父母佈局更改爲線性佈局。這會得到期望的結果。

XML文件將是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white_three" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="vertical"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/orderList" 
      android:layout_height="match_parent" 
      android:layout_width="match_parent"> 
     </android.support.v7.widget.RecyclerView> 

     <TextView 
      android:id="@+id/errorLoadingText" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:textSize="15sp" 
      android:visibility="gone" 
      android:layout_marginTop="120dp" 
      android:gravity="center"/> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/white_three" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/paymentButtonTop" 
      android:layout_width="match_parent" 
      android:layout_height="43dp" 
      android:background="@drawable/button_radius_toggle_confirm" 
      android:layout_marginTop="15dp" 
      android:layout_marginStart="15dp" 
      android:layout_marginEnd="15dp" 
      android:layout_marginBottom="75dp" 
      android:text="@string/prepayment" 
      android:textColor="@color/warm_grey_two" 
      android:enabled="false" 
      android:textSize="17sp" 
      android:gravity="center" /> 

     <TextView 
      android:id="@+id/paymentButton" 
      android:layout_width="match_parent" 
      android:layout_height="43dp" 
      android:background="@drawable/button_radius_toggle_confirm" 
      android:layout_margin="15dp" 
      android:visibility="gone" 
      android:enabled="false" 
      android:textColor="@color/warm_grey_two" 
      android:text="@string/prepayment" 
      android:textSize="17sp" 
      android:gravity="center" /> 

    </LinearLayout> 

</LinearLayout> 
1

你必須移動第一Linear Layout下來。 只需切換兩個線性佈局。

+0

嗯..嘗試和按鈕消失,它的背後隱藏的,而不是現在 – stackyyflow

2

雖然這不是很好的做法,LinearLayoutRelativeLayout二人性能問題裏面,你可以達到你想要通過設置在底部的LinearLayout屬性android:layout_alignParentBottom="true"並通過頂部LinearLayout設置android:layout_above="@+id/idOfBottomLinearLayout"什麼。

在代碼:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white_three" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <LinearLayout 
     android:layout_above="@+id/bottomLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/orderList" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:layout_width="match_parent"/> 

     <TextView 
      android:id="@+id/errorLoadingText" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:textSize="15sp" 
      android:visibility="gone" 
      android:layout_marginTop="120dp" 
      android:gravity="center"/> 

    </LinearLayout> 

    <LinearLayout 
     android:id = "@+id/bottomLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/white_three" 
     android:layout_alignParentBottom="true" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/paymentButtonTop" 
      android:layout_width="match_parent" 
      android:layout_height="43dp" 
      android:background="@drawable/button_radius_toggle_confirm" 
      android:layout_marginTop="15dp" 
      android:layout_marginStart="15dp" 
      android:layout_marginEnd="15dp" 
      android:layout_marginBottom="75dp" 
      android:text="@string/prepayment" 
      android:textColor="@color/warm_grey_two" 
      android:enabled="false" 
      android:textSize="17sp" 
      android:gravity="center" /> 

     <TextView 
      android:id="@+id/paymentButton" 
      android:layout_width="match_parent" 
      android:layout_height="43dp" 
      android:background="@drawable/button_radius_toggle_confirm" 
      android:layout_margin="15dp" 
      android:visibility="gone" 
      android:enabled="false" 
      android:textColor="@color/warm_grey_two" 
      android:text="@string/prepayment" 
      android:textSize="17sp" 
      android:gravity="center" /> 

    </LinearLayout> 

</RelativeLayout>