我的 Android 应用程序出现异常行为。我有这个 XML 配置
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"/>
<TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:textAppearance="?attr/textAppearanceListItem" />
</LinearLayout>
但是当我运行应用程序时,结果是这样的
图像1'、2'、3'是正确的,但为什么第一行的第三张图像不正确?此外,在同一屏幕和其他列中还有另一个图像具有相同的问题。所有图像具有相同的大小
最佳答案
- 设置宽度match_parent
- 添加 android:adjustViewBounds .
Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable.
<ImageView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
关于Android:ScaleType ="fitXY"不适用于所有图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45624901/