【问题标题】:Xml scale animation of ImageView makes the image aliasedImageView的xml缩放动画使图像出现锯齿
【发布时间】:2011-04-12 14:57:01
【问题描述】:

我有一个小 xml 动画,可以为我的布局中的几个 ImageView 设置动画。实际上它是来自 api demos sdk 示例的波形动画。该动画将图像放大然后缩小到其原始大小,因此它看起来有点像波浪。问题是当图像被放大时,它看起来很糟糕,边缘有锯齿并且图像是块状的。 我的动画是这样的:

<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:duration="100" />
    <scale
        android:fromXScale="0.5" android:toXScale="1.25"
        android:fromYScale="0.5" android:toYScale="1.25"
        android:pivotX="50%" android:pivotY="50%"
        android:duration="200" />
    <scale 
        android:fromXScale="1.25" android:toXScale="1.0"
        android:fromYScale="1.25" android:toYScale="1.0"
        android:pivotX="50%" android:pivotY="50%"
        android:startOffset="200"
        android:duration="100" />
</set>

我尝试了,而不是直接在 ImageView 的 src 中加载图像,而是将其包装在 xml 位图元素中并启用抗锯齿和过滤,但没有任何区别。

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/myimage_img"
    android:antialias="true"
    android:filter="true"
    android:tileMode="disabled"
/>

我的 ImageView 看起来像这样:

<ImageView android:src="@drawable/myimage" android:layout_height="wrap_content" android:layout_margin="5dp" android:adjustViewBounds="true" android:layout_width="fill_parent" android:scaleType="centerInside"></ImageView>

还请注意,图像并未真正放大。图像本身比它出现在屏幕上的要大。它在 ImageView 内居中。但是看起来动画不是使用原始图像以不同的大小渲染它,而是使用 ImageView 中的缩小图像并再次放大它。

你能帮我让我的图像在动画时看起来很平滑吗?

【问题讨论】:

    标签: android animation filter imageview


    【解决方案1】:

    根据您的设备 DPI,您是否有合适的图像尺寸?即使图像在您的 PC 屏幕上看起来很大,但由于每英寸的点数较多,图像在手机屏幕上可能会很小。如果是这种情况,Android 将不得不放大图像。

    【讨论】:

    • 是的,我的图片尺寸合适。正如我所提到的,图像实际上是按比例缩小的,我还在模拟器和真实设备上测试了小 dpi 和高 dpi,没有区别 - 行为仍然如我上面所述。
    猜你喜欢
    • 1970-01-01
    • 2021-02-12
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-13
    • 2016-04-24
    相关资源
    最近更新 更多