首页 > 解决方案 > 为什么我的图像没有显示在 imageView 中?

问题描述

所以我正在使用 android studio 处理我的项目。我用 CardView 创建了一个简单的 xml,并在其中使用了 ImageView。代码如下:

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

但是当我运行应用程序时,图像不会出现。它应该看起来像这样,但它看起来 像这样。是不是因为图片太大?(我从谷歌图片下载了img)。如何解决这个问题?

标签: xmlimageviewandroid-imageviewandroid-cardview

解决方案


你可以试试这个

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

推荐阅读