RecyclerView将按钮推入不可见区域

时间:2018-01-14 16:11:17

标签: java android android-recyclerview

如果有超过5个项目,RecyclerView会按下可见区域下方的按钮。我该如何解决这个问题?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.dolinsek.elias.cashcockpit.BankAccountsFragment"
android:orientation="vertical">

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

<Button
    android:id="@+id/button_create_bank_accounts"
    style="@style/Widget.AppCompat.Button.Colored"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_margin="5dp"
    android:text="@string/create_account"
    android:textColor="#ffffff" />

2 个答案:

答案 0 :(得分:2)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.dolinsek.elias.cashcockpit.BankAccountsFragment"
android:orientation="vertical">

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

<Button
    android:id="@+id/button_create_bank_accounts"
    style="@style/Widget.AppCompat.Button.Colored"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_margin="5dp"
    android:text="@string/create_account"
    android:textColor="#ffffff" />

答案 1 :(得分:0)

尝试以下...

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.dolinsek.elias.cashcockpit.BankAccountsFragment"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_bank_accounts"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="50dp"
        />

    <Button
        android:layout_alignParentBottom="true"
        android:id="@+id/button_create_bank_accounts"
        style="@style/Widget.AppCompat.Button.Colored"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:layout_margin="5dp"
        android:text="@string/create_account"
        android:textColor="#ffffff" />
</RelativeLayout>