Android:ScaleType ="fitXY"不适用于所有图像

标签 android xml android-layout imageview

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

但是当我运行应用程序时,结果是这样的

enter image description here

图像1'、2'、3'是正确的,但为什么第一行的第三张图像不正确?此外,在同一屏幕和其他列中还有另一个图像具有相同的问题。所有图像具有相同的大小

最佳答案

  1. 设置宽度ma​​tch_parent
  2. 添加 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/

相关文章:

java - BaseGameUtils 无法解析符号 android 在 : "com.google.android.gms.games.Games"

Android studio 3.0 报错Unable to resolve dependency for ':app@debugAndroidTest/

android - 错误 "OMX_GetExtensionIndex failed"在 MediaCodec 的上下文中意味着什么,我该如何解决它?

java - 所有带有 Intent 的按钮都不起作用

java - 窗口已经聚焦,忽略我的通知应用程序中 : com. android.internal.view 的焦点增益

android - 检索 Listview 行数据(由两个 TextView 组成)

android - adb remount 总是需要 adb root

xml - XSLT:如何在另一个模板中重用一个模板

ruby - XML解析元素和元素属性到数组中

java - 如何强制 XSLT 结果树使用特定的默认命名空间进行序列化?