【问题标题】:Items on a map in a RecyclerView are not fully displayedRecyclerView 中地图上的项目未完全显示
【发布时间】:2022-12-15 14:25:56
【问题描述】:

我有一个 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>

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

这就是它的呈现方式:

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

【问题讨论】:

    标签: android android-studio android-layout


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2019-09-09
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多