【问题标题】:Smoother animation ImageSwitcher更流畅的动画 ImageSwitcher
【发布时间】:2014-02-06 22:03:13
【问题描述】:

我正在使用 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 淡出:*

<?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>

【问题讨论】:

    标签: android animation smooth imageswitcher


    【解决方案1】:

    您可以做几件事来改进动画。首先,通过添加应用程序属性在您的 Android Manfiest 中启用硬件加速:

    android:hardwareAccelerated="true"
    

    接下来,尝试一些不同的 *interpolator*s。您可能会发现@android:anim/linear 更流畅。

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

    【讨论】:

    • 哇,完美!我应该在动画之后设置 hardwareAcceleration="false" 吗?
    • @Matwosk 您可以将设置保留在清单中。如果您愿意,有一种方法可以通过编程方式禁用硬件加速,但在大多数情况下,将其保持打开状态就可以了。
    • 将此添加到我的清单后,我在一项活动中丢失了背景图像。知道为什么吗?
    • 发现硬件加速对图像大小有限制
    • @Msmit1993 是的,位图最多只能是设备屏幕的大小。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-13
      • 1970-01-01
      • 2012-01-13
      • 1970-01-01
      • 2014-01-16
      • 2013-05-12
      • 2014-10-30
      相关资源
      最近更新 更多