【问题标题】:Images 'fill' ImageViews differently on different versions of Android?图像在不同版本的 Android 上以不同方式“填充”ImageViews?
【发布时间】:2021-04-13 07:45:56
【问题描述】:

不知道如何正确命名它,但基本上我的图像在不同版本的 Android 之间填充它们的 ImageViews 不同。

例子:

从左边开始是 4.1.1、4.4.4 和 5.0.0。都在同一台设备上 (Nexus 4)。

KitKat 和 Lollipop 符合预期,但无论我做什么,无论屏幕密度如何,Jellybean 都未能效仿。

我正在使用 Picasso 加载图像,并使用 RecyclerView/CardView 组合来加载列表。

代码并没有什么特别之处,而且它在 Picasso 方面相当标准,但如果有人想要,这里是 ImageView 的 XML:

        <ImageView
            android:id="@+id/news_image"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:contentDescription="@string/news_image_content_description"
            android:scaleType="fitCenter"
            android:cropToPadding="false"
            android:adjustViewBounds="true"/>

【问题讨论】:

  • 一时兴起,我检查了开发文档并在adjustViewBounds 下找到了这个:“如果应用程序的目标 API 级别为 17 或更低,adjustViewBounds 将允许可绘制对象缩小视图边界,但是在所有情况下都不会增长以填充可用的测量空间。“我想我已经找到了问题,但仍在努力寻找解决方案。

标签: android android-layout


【解决方案1】:

终于明白了。正如我在那条评论中提到的,在 API 17 之前,它不会让可绘制对象增长以填充 ImageView,只会缩小。所以我的解决方案是使用 Picasso 来放大图像并让系统缩小它的大小,根据来自SO post的观察结果@

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-25
    • 1970-01-01
    • 2013-01-30
    • 2015-12-06
    • 2016-07-26
    相关资源
    最近更新 更多