Home > Software engineering >  Image View not rendering at run time
Image View not rendering at run time

Time:09-17

I am setting up a recylcerview but it is not showing any images when the app runs, but they do show up on the design view, I tried both AppcompatImageView and ImageView but both failed. Only the text View shows. Your help is greatly appreciated

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

CodePudding user response:

You are using tools namespace in tools:background which is used for design purposes, not the runtime purpose; so, you'd see the image on android studio layout design, but not when you run the app.

To fix this, use android namespace instead:

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

Please check documentation for more info

  • Related