图像视图未在 运行 时间呈现

Image View not rendering at run time

我正在设置 recylcerview,但应用程序运行时它不显示任何图像,但它们确实显示在设计视图中,我尝试了 AppcompatImageViewImageView 但都失败了。仅显示文本视图。非常感谢您的帮助

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.cardview.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:cardView="http://schemas.android.com/apk/res-auto"
    android:id="@+id/carView"
    android:layout_width="match_parent"
    android:layout_height="90dp"
    cardView:cardCornerRadius="8dp"
    cardView:cardElevation="2dp"
    android:layout_margin="5dp">
    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.appcompat.widget.AppCompatImageView
            android:elevation="2dp"
            android:id="@+id/imageb"
            android:layout_width="50dp"
            android:layout_height="50dp"
            cardView:layout_constraintBottom_toBottomOf="parent"
            cardView:layout_constraintEnd_toEndOf="parent"
            cardView:layout_constraintTop_toTopOf="parent"
            tools:background="@drawable/ic_baseline_cloud_download_24" />

        <TextView
            android:id="@+id/recording_title"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_margin="8dp"
            android:layout_marginStart="8dp"
            android:fontFamily="sans-serif-smallcaps"
            android:gravity="center_vertical"
            android:lines="2"
            android:text="Title"
            android:padding="4dp"
            android:textAppearance="@style/PostTitleText"
            android:textColor="@android:color/black"
            android:textSize="12sp"
            android:textStyle="bold"
            cardView:layout_constraintBottom_toBottomOf="parent"
            cardView:layout_constraintStart_toStartOf="parent"
            cardView:layout_constraintTop_toTopOf="parent" />
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>

您正在 tools:background 中使用 tools 命名空间,这是用于设计目的,而不是 运行时间目的;因此,您会在 android 工作室布局设计中看到图像,但在 运行 应用程序中看不到图像。

要解决此问题,请改用 android 命名空间:

<androidx.appcompat.widget.AppCompatImageView
    ....
    android:background="@drawable/ic_baseline_cloud_download_24" />

check documentation了解更多信息