更平滑的动画ImageSwitcher

时间:2014-02-06 22:03:13

标签: android animation smooth imageswitcher

我使用fade_in和fade_out动画avaible android.R.anim.fade_in(fade_out)。基本上我可以改变动画的持续时间,但无论它的0.5秒或2秒动画是否仍然不平滑。有没有办法让淡入/淡出动画更流畅?非常感谢!

代码:

imageSwitcher = (ImageSwitcher) findViewById(R.id.imageswitcher);

    slide_in_left = AnimationUtils.loadAnimation(this, R.anim.fade);
    slide_out_right = AnimationUtils.loadAnimation(this, R.anim.fade_out);

    imageSwitcher.setInAnimation(slide_in_left);
    imageSwitcher.setOutAnimation(slide_out_right);

* XML fade_out:*

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha
        android:duration="1500"
        android:fromAlpha="1.0"
        android:toAlpha="0.0"
        android:interpolator="@android:anim/accelerate_interpolator" />
</set>

2 个答案:

答案 0 :(得分:3)

您可以采取一些措施来改进动画。首先,通过添加应用程序属性来启用Android Manfiest中的硬件加速:

android:hardwareAccelerated="true"

接下来,尝试一些不同的*插值器*。您可能会发现@android:anim/linear更顺畅。

最后,如果这不起作用,您可以始终以编程方式使用Property Animations(对于较旧的API版本,您可以使用NineOldAndroids)。

答案 1 :(得分:0)

对我有用的还有最小化我的应用的背景图片的文件大小。

相关问题