Android Studio RecyclerView中Map上的项目未完全显示

wlsrxk51  于 2022-12-13  发布在  Android
关注(0)|答案(2)|浏览(833)

我有一个RecyclerView,我想在其中显示一个项目列表。到目前为止,我已经为每个元素创建了布局。问题是并不是所有内容都显示出来了。数据都在那里,这不是原因,这完全是关于显示的。
下面是我的布局:

<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.cardview.widget.CardView
    android:clickable="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="6dp"
    android:layout_marginBottom="16dp"
    android:padding="10dp"
    app:cardUseCompatPadding="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="16dp"
        android:padding="10dp">

        <ImageView
            android:id="@+id/rv_list_main_img"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:scaleType="centerCrop"
            android:src="@drawable/longtime"></ImageView>

                <ImageView
                    android:id="@+id/main_list_rv_sender_img"
                    android:background="@drawable/imageborder"
                    android:padding="10dp"
                    android:scaleType="fitXY"

                    android:src="@drawable/shorttime"
                    android:layout_width="100dp"
                    android:layout_height="100dp"></ImageView>

                <TextView
                    android:id="@+id/main_list_rv_sender_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Abador"
                    android:layout_marginTop="16dp"
                    android:fontFamily="@font/baumans"
                    android:textSize="23sp"
                    android:textStyle="bold"></TextView>

                <TextView
                    android:id="@+id/main_list_rv_place"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Bella Vista, PY"
                    android:textSize="16sp"></TextView>

                <TextView
                    android:id="@+id/main_list_rv_price"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:gravity="bottom"
                    android:text="600 USD/mtl"
                    android:textSize="23sp"
                    android:textStyle="bold"></TextView>

            <TextView
                android:id="@+id/main_list_rv_desc"
                android:layout_width="260dp"
                android:layout_height="60dp"
                android:layout_alignParentLeft="true"
                android:gravity="left"
                android:maxLength="200"
                android:maxLines="2"
                android:text="Beschreibung Haus sdf sdfe Beschreibung Haus sdf sdfe"
                android:textSize="17sp"
                android:textStyle="bold"></TextView>

            <ImageButton
                android:id="@+id/main_list_rv_message_btn"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_alignParentRight="true"
                android:backgroundTint="@color/white"
                android:scaleType="centerCrop"
                android:src="@drawable/send"></ImageButton>

    </LinearLayout>
</androidx.cardview.widget.CardView>

</LinearLayout>

列表中的项目应如下所示:

这就是它的呈现方式:

正如您所看到的,较小的图像被截断,下面的所有文本甚至都没有显示

ttcibm8c

ttcibm8c1#

使您的视图高度换行和文本视图高度换行(复制文本)

<LinearLayout 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="wrap_content"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:elevation="6dp"
        android:padding="10dp"
        app:cardUseCompatPadding="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="16dp"
            android:orientation="vertical"
            android:padding="10dp">

            <ImageView
                android:id="@+id/rv_list_main_img"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="centerCrop"
                android:src="@drawable/ic_launcher_background" />

            <ImageView
                android:id="@+id/main_list_rv_sender_img"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:padding="10dp"
                android:scaleType="fitXY"
                android:src="@drawable/ic_launcher_background" />

            <TextView
                android:id="@+id/main_list_rv_sender_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:text="Abador"
                android:textSize="23sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/main_list_rv_place"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Bella Vista, PY"
                android:textSize="16sp" />

            <TextView
                android:id="@+id/main_list_rv_price"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:gravity="bottom"
                android:text="600 USD/mtl"
                android:textSize="23sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/main_list_rv_desc"
                android:layout_width="260dp"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:gravity="left"
                android:maxLength="200"
                android:maxLines="2"
                android:text="Beschreibung Haus sdf sdfe Beschreibung Haus sdf sdfe"
                android:textSize="17sp"
                android:textStyle="bold" />

            <ImageButton
                android:id="@+id/main_list_rv_message_btn"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_alignParentRight="true"
                android:backgroundTint="@color/white"
                android:scaleType="centerCrop"
                android:src="@drawable/ic_launcher_background" />

        </LinearLayout>
    </androidx.cardview.widget.CardView>

</LinearLayout>
wwwo4jvm

wwwo4jvm2#

更改CardView android:layout_height="wrap_parent"

相关问题