Каждая карта в представлении карты имеет разную ширину - PullRequest
0 голосов
/ 26 января 2019

Я использую AndroidStudio 3.2.1 и Java.У меня есть RecyclerView, где элементы отображаются с использованием CardView.Мой код работает нормально.Однако каждая карта имеет разную ширину в зависимости от ее содержимого.Что мне нужно, так это то, что все карты имеют одинаковую ширину с родительской шириной.Я думаю, что это проблема макета.Я надеюсь, что кто-то знает, как это исправить.Спасибо.

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

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="8dp">

            <ImageView
                android:id="@+id/imageView"
                android:layout_width="120dp"
                android:layout_height="90dp"
                android:padding="4dp" />

            <TextView
                android:id="@+id/textViewTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_toRightOf="@id/imageView"
                android:text="Apple MacBook Air Core i5 5th Gen - (8 GB/128 GB SSD/Mac OS Sierra)"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"
                android:textColor="#000000" />

            <TextView
                android:id="@+id/textViewShortDesc"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/textViewTitle"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="5dp"
                android:layout_toRightOf="@id/imageView"
                android:text="13.3 Inch, 256 GB"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Small" />

            <TextView
                android:id="@+id/textViewRating"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/textViewShortDesc"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="5dp"
                android:layout_toRightOf="@id/imageView"
                android:background="@color/colorPrimary"
                android:paddingLeft="15dp"
                android:paddingRight="15dp"
                android:text="4.7"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Small.Inverse"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/textViewPrice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/textViewRating"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="5dp"
                android:layout_toRightOf="@id/imageView"
                android:text="INR 56990"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                android:textStyle="bold" />

        </RelativeLayout>

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

</LinearLayout>

Ожидается равная ширина для каждой карты, которая покрывает родительскую ширину.Тем не менее, фактический результат заключается в том, что каждая карта имеет различную ширину в зависимости от ее содержимого

1 Ответ

0 голосов
/ 26 января 2019

Просто измените свойство TextViews в соответствии с родительским.Если это не сработает, поместите вашего родственника в LinearLayout или замените его на LinearLayout с ориентацией, установленной на вертикаль

android:layout_width="match_parent"

Возможно, вам также понадобится добавить это.

app:cardUseCompatPadding="true"
...