ImageView的Xml缩放动画使图像出现锯齿
我有一个小的 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>
我尝试将图像包装在 xml 位图元素中并启用抗锯齿和过滤,而不是直接在 ImageView 的 src 中加载图像,但这没有什么区别。
<?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 中缩小尺寸的图像并再次放大。
你能帮我让我的图像在动画时显得平滑吗?
I have a little xml animation that animates few ImageViews inside my layout. Actually it is the wavescale animation from the api demos sdk example. This animation scales the image up and then down to its original size so it looks sort of wave. The problem is when the image is upscaled it looks very bad, the edges are aliased and the image is blocky.
My animation looks like this:
<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>
I tried, instead of loading the image directly in the src of the ImageView, to wrap it in a xml bitmap element and enable antialiasing and filtering but it makes no difference.
<?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"
/>
And my ImageView looks like this:
<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>
Please also note that the image is not really upscaled. The image itself is bigger that it appears on the screen. It is centered inside the ImageView. But looks like the animation is not using the original image to render it with different size, but using the downscaled image from the ImageView and scaling it up again.
Can you please help me to make my image appear smooth when it is animated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的设备 DPI,您是否有合适的图像尺寸?尽管图像在 PC 屏幕上看起来很大,但由于每英寸的点数较多,图像在手机屏幕上可能会很小。如果是这种情况,Android 将不得不放大图像。
Do you have the proper image size based on your device DPI? Even though an image looks large on your PC screen, an image may be small on the phone's screen due to a larger number of dots per inch. If this is the case, Android will have to scale the image up.