2016-05-21 109 views
0

我試圖把按鈕的RecyclerView以下,以這樣的方式,當你滾動一路下跌的RecyclerView,應該有一個按鈕(上一頁/下一頁)按鈕下面RecyclerView

我的XML嘗試在下面給出。但RecyclerView需要所有的空間。

請注意我已經試過把layout_height=0layout_weight=1,但它仍然無法正常工作。

<?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" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="0dp" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="0dp" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="com.example.app.home" 
tools:showIn="@layout/app_bar_home"> 

<ProgressBar 
    android:id="@+id/progressBar1" 
    style="?android:attr/progressBarStyle" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true"/> 

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

</android.support.v7.widget.RecyclerView> 

<LinearLayout 
    android:id="@+id/next_prev_button" 
    android:layout_below="@+id/rv_homepost" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="50dp" 
    android:gravity="center_vertical"> 

    <Button 
     android:id="@+id/prev_button" 
     style="@style/Widget.AppCompat.Button.Colored" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="-4dp" 
     android:enabled="true" 
     android:text="Previous" /> 

    <View 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_weight="1" /> 

    <Button 
     android:id="@+id/next_button" 
     style="@style/Widget.AppCompat.Button.Colored" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="-4dp" 
     android:enabled="true" 
     android:text="Next" /> 
    </LinearLayout> 
</LinearLayout> 
+0

你只是缺少'機器人:方向= 「垂直」'在你的根'LinearLayout'否則它看起來不錯 – Sharj

回答

0

只是試試這個....有一些變化可能對你有用。

你忘android:orientation="vertical"財產線性佈局..

<?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" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="com.example.app.home" 
tools:showIn="@layout/app_bar_home"> 

<ProgressBar 
    android:id="@+id/progressBar1" 
    style="?android:attr/progressBarStyle" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true"/> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/rv_homepost" 
    android:layout_width="match_parent" 
    android:layout_marginTop="5dp" 
    android:layout_height="0dp" 
    android:layout_weight="7"> 

</android.support.v7.widget.RecyclerView> 

<LinearLayout 
    android:id="@+id/next_prev_button" 
    android:layout_below="@+id/rv_homepost" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="50dp" 
    android:layout_weight="1" 
    android:gravity="center_vertical"> 

    <Button 
     android:id="@+id/prev_button" 
     style="@style/Widget.AppCompat.Button.Colored" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="4dp" 
     android:layout_weight="1" 
     android:enabled="true" 
     android:text="Previous" /> 

    <View 
     android:layout_width="1dp" 
     android:layout_height="match_parent" /> 

    <Button 
     android:id="@+id/next_button" 
     style="@style/Widget.AppCompat.Button.Colored" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="4dp" 
     android:layout_weight="1" 
     android:enabled="true" 
     android:text="Next" /> 
    </LinearLayout> 
</LinearLayout> 

享受編碼......