RecyclerView 设计更改从数组中获取

RecyclerView Design Changing fetch from array

如果我从 RecyclerView 中的数组中获取数据,屏幕的设计会发生变化,但是当数据定义为静态时(在 XML 中),设计是正确的,我应该怎么办怎样才能使预览中的设计保持原样?

我正在使用 Fragments 和 recyclerView 来扩充数组中的数据

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">


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

    <LinearLayout
        android:id="@+id/rentInvoice"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="25dp"
        android:layout_marginRight="25dp"
        android:layout_marginBottom="20dp"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

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

                <TextView
                    android:id="@+id/paymentsDate"
                    android:textStyle="bold"
                    android:textColor="@color/colorFontHeading"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/date"
                    android:textSize="18sp" />

                <TextView
                    android:id="@+id/paymentsReceiptNumber"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/reciept_number" />
                <TextView
                    android:id="@+id/paymentsData"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="PaymentData" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="end">


                <TextView
                    android:id="@+id/paymentsAmount"
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/rs_000000"

                    />
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right"
                    android:src="@drawable/ic_navigate_next_black_24dp" />
            </LinearLayout>

        </LinearLayout>

    </LinearLayout>

以上是布局的XML代码
下面是RecyclerView所在的XML代码

<?xml version="1.0" encoding="utf-8"?>
<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=".Fragments.PaymentsFragment"
android:orientation="vertical">

<SearchView

    android:queryHint="@string/search"
    android:layout_margin="15dp"
    android:id="@+id/searchViewPayments"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/search_view_rounded"
    android:layoutDirection="rtl"/>


<LinearLayout
    android:id="@+id/recyclerViewLayout"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v7.widget.RecyclerView

        android:id="@+id/paymentsRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


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



</LinearLayout>

如果要实现最左布局和最右布局,可以使用RelativeLayout作为父级,使用alignParentEndalignParentStart。这应该是您的 LinearLayout 标签内的布局,id 为 rentInvoice:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:layout_centerVertical="true"
        android:layout_alignParentStart="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        ...

    </LinearLayout>

    <LinearLayout
        android:layout_centerVertical="true"
        android:layout_alignParentEnd="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/paymentsAmount"
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/rs_000000" />

        ...

    </LinearLayout>

</RelativeLayout>