【问题标题】:How to control duration of transition in ImageSwitcher Android如何控制 ImageSwitcher Android 中的过渡持续时间
【发布时间】:2012-05-08 11:34:53
【问题描述】:

我有一个 ImageSwitcher,我正在使用它来创建幻灯片。 我可以控制图像显示的持续时间,但如何控制图像之间过渡的持续时间。我想增加该持续时间,因为上一张图片的 outAnimation 和下一张图片的 inAnimation 看起来像是合并了,看起来不太好。

【问题讨论】:

    标签: android timer slideshow android-image imageswitcher


    【解决方案1】:

    为您的 ImageSwitcher 定义自定义进出动画:

    ImageSwitcher imageSwitcher = (ImageSwitcher) findViewById(R.id.ImageSwitcher);
    imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
        R.anim.custom_fade_in));
    imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
        R.anim.custom_fade_out));
    

    并在您的动画 xml 中设置您的持续时间:

    <?xml version="1.0" encoding="UTF-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <translate
        ....
        android:duration="1000"/>
    </set> 
    

    【讨论】:

    • 谢谢!奇迹般有效。我只需要更改 XML 中的持续时间。我可以在没有自定义 xml 的情况下做到这一点。我可以使用 android 提供的 ImageSwitcher API 演示。但是,如果您的意思是自定义将其捆绑在您的应用程序中,而不是使用内置的 android.R.anim. 常量,那么您是对的 :)
    猜你喜欢
    • 2019-01-25
    • 2019-10-28
    • 1970-01-01
    • 2014-04-30
    • 2020-10-17
    • 1970-01-01
    • 1970-01-01
    • 2012-10-07
    • 2014-02-17
    相关资源
    最近更新 更多