Search code examples
xmlimageviewandroid-imageviewandroid-cardview

Why does my image doesn't show in imageView?


so I am working with my project using android studio. I created a simple xml with CardView and used an ImageView in it. Code bellow:

<androidx.cardview.widget.CardView
                android:layout_width="120dp"
                android:layout_height="150dp"
                android:layout_centerInParent="true"
                android:layout_marginStart="5dp"
                android:layout_marginEnd="5dp"
                app:cardBackgroundColor="@color/white"
                app:cardCornerRadius="20dp"
                app:cardElevation="3dp"
                app:cardMaxElevation="20dp">


                <ImageView
                    android:id="@+id/imageView3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    tools:srcCompat="@drawable/vector_illustration" />
            </androidx.cardview.widget.CardView>

But when I run the app, the image doesn't appear. It should be look like this, but it look like this instead. Is it because the image is too big?(i download the img from google image). How to fix this?


Solution

  • You can try this

    xmlns:app="http://schemas.android.com/apk/res-auto"
    .
    ...
    ...
    <androidx.appcompat.widget.AppCompatImageView
       android:id="@+id/imageView3"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       app:srcCompat="@drawable/vector_illustration"
    />