将recyclelerview设置在alignParentBottom布局上方

时间:2016-12-21 20:59:24

标签: android android-layout

我有recyclerviewbutton alignParentBottom。该视图看起来不错,但我的recyclerview项的最后一行被按钮阻止,因为我的recyclerview似乎是" "按钮和按钮上方的。我该如何解决这个问题?

这是我的布局:

<?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>

3 个答案:

答案 0 :(得分:2)

虽然在LinearLayout二重奏性能问题中使用RelativeLayout不是一个好习惯,但您可以通过在底部LinearLayout上设置属性android:layout_alignParentBottom="true"并设置{{1}来实现您想要的效果顶部android:layout_above="@+id/idOfBottomLinearLayout"

在代码中:

LinearLayout

答案 1 :(得分:1)

您必须先向下移动Linear Layout。 只需切换两个线性布局即可。

答案 2 :(得分: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>