CardView в RecyclerView нет пробелов и текстовое представление вне макета - PullRequest
2 голосов
/ 27 марта 2019

У меня есть CardView, который я помещаю в представление переработчика. Представление карты, которое я делаю, не имеет разрыва между собой, хотя я уже добавил поля и отступы. также текст находится вне поля зрения карты.

Это результат моего кода, текст за пределами экрана и нет пропуска между просмотром карты:

enter image description here

Это список xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 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="120dp"
    android:layout_margin="5dp">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/tv_sales_invoice"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="invoice"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/tv_sales_date"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="date"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/tv_sales_invoice" />

        <View
            android:id="@+id/top_line"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginTop="5dp"
            android:background="@color/colorBlack"
            app:layout_constraintTop_toBottomOf="@+id/tv_sales_date" />

        <TextView
            android:id="@+id/sales_itemname_header"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:text="@string/item_name"
            android:textSize="16sp"
            android:textStyle="bold"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/top_line" />

        <TextView
            android:id="@+id/sales_itemqty_header"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/item_qty"
            android:textSize="16sp"
            android:textStyle="bold"
            app:layout_constraintLeft_toRightOf="@+id/sales_itemname_header"
            app:layout_constraintRight_toRightOf="@+id/sales_itemprice_header"
            app:layout_constraintTop_toTopOf="@+id/sales_itemname_header" />

        <TextView
            android:id="@+id/sales_itemprice_header"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/item_price"
            android:textSize="16sp"
            android:textStyle="bold"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="@+id/sales_itemname_header" />

        <View
            android:id="@+id/mid_line"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@color/colorBlack"
            app:layout_constraintTop_toBottomOf="@+id/sales_itemname_header" />

        <TextView
            android:textAlignment="textStart"
            android:id="@+id/tv_sales_type"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="item"
            android:textSize="18sp"
            app:layout_constraintLeft_toLeftOf="@+id/sales_itemname_header"
            app:layout_constraintRight_toRightOf="@+id/sales_itemname_header"
            app:layout_constraintTop_toBottomOf="@+id/sales_itemname_header" />

        <TextView
            android:id="@+id/tv_sales_qty"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="qty"
            android:textSize="18sp"
            app:layout_constraintLeft_toLeftOf="@+id/sales_itemqty_header"
            app:layout_constraintRight_toRightOf="@+id/sales_itemqty_header"
            app:layout_constraintTop_toBottomOf="@+id/sales_itemqty_header" />

        <TextView
            android:textAlignment="viewEnd"
            android:id="@+id/tv_sales_price"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/price"
            android:textSize="18sp"
            app:layout_constraintLeft_toLeftOf="@+id/sales_itemprice_header"
            app:layout_constraintRight_toRightOf="@+id/sales_itemprice_header"
            app:layout_constraintTop_toBottomOf="@+id/sales_itemprice_header" />

    </android.support.constraint.ConstraintLayout>


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

это макет представления переработчика:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
    tools:context=".SalesHistoryActivity">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/tv_sales_history"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/sales_history"
            android:textSize="25dp"
            android:textStyle="bold"
            app:layout_constraintTop_toTopOf="parent" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/sales_recycler"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:padding="10dp"
            android:nestedScrollingEnabled="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/tv_sales_history"></android.support.v7.widget.RecyclerView>


    </android.support.constraint.ConstraintLayout>
</ScrollView>

Ответы [ 2 ]

0 голосов
/ 28 марта 2019

Ниже прилагаемый код решит вашу проблему. Надеюсь, это поможет вам. Пожалуйста, попробуйте утвердить его, если это полезно.

Если у вас есть другие вопросы, пожалуйста, задавайте их в разделе комментариев ниже. Я тоже постараюсь решить эту проблему.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/cardView"
    android:layout_width="match_parent"
    android:layout_height="120dp"
    android:layout_margin="5dp">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/tv_sales_invoice"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="invoice"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/tv_sales_date"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="date"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/tv_sales_invoice" />

        <View
            android:id="@+id/top_line"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginTop="5dp"
            android:background="@color/colorBlack"
            app:layout_constraintTop_toBottomOf="@+id/tv_sales_date" />

        <TextView
            android:id="@+id/sales_itemname_header"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:text="item_name"
            android:textSize="16sp"
            android:textStyle="bold"
            app:layout_constraintEnd_toStartOf="@+id/sales_itemqty_header"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/top_line" />

        <TextView
            android:id="@+id/sales_itemqty_header"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:text="item_qty"
            android:textSize="16sp"
            android:textStyle="bold"
            app:layout_constraintEnd_toStartOf="@+id/sales_itemprice_header"
            app:layout_constraintLeft_toRightOf="@+id/sales_itemname_header"
            app:layout_constraintTop_toTopOf="@+id/sales_itemname_header" />

        <TextView
            android:id="@+id/sales_itemprice_header"
            android:layout_width="90dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Item price"
            android:textSize="16sp"
            android:textStyle="bold"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintStart_toEndOf="@id/sales_itemqty_header"
            app:layout_constraintTop_toTopOf="@+id/sales_itemname_header" />

        <View
            android:id="@+id/mid_line"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@color/colorBlack"
            app:layout_constraintTop_toBottomOf="@+id/sales_itemname_header" />

        <TextView
            android:id="@+id/tv_sales_type"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="Lorem Ipsum is simply dummy text"
            android:textAlignment="textStart"
            android:textSize="18sp"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintLeft_toLeftOf="@+id/sales_itemname_header"
            app:layout_constraintRight_toRightOf="@+id/sales_itemname_header"
            app:layout_constraintTop_toBottomOf="@+id/mid_line" />

        <TextView
            android:id="@+id/tv_sales_qty"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="qty"
            android:textSize="18sp"
            app:layout_constraintLeft_toLeftOf="@+id/sales_itemqty_header"
            app:layout_constraintRight_toRightOf="@+id/sales_itemqty_header"
            app:layout_constraintTop_toBottomOf="@+id/sales_itemqty_header" />

        <TextView
            android:id="@+id/tv_sales_price"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:gravity="end"
            android:text="Rp 13000.00"
            android:textSize="18sp"
            app:layout_constraintLeft_toLeftOf="@+id/sales_itemprice_header"
            app:layout_constraintRight_toRightOf="@+id/sales_itemprice_header"
            app:layout_constraintTop_toBottomOf="@+id/sales_itemprice_header" />

    </android.support.constraint.ConstraintLayout>


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

enter image description here

0 голосов
/ 27 марта 2019

Вы должны использовать wrap_content в своей карточке.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 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="wrap_content"
 android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp">
 ....
...