【问题标题】:Background animation image on ProgressBar on Android?Android上ProgressBar上的背景动画图像?
【发布时间】:2012-12-13 16:54:19
【问题描述】:

当您需要更改 ProgressBar 的背景图片时,应该采取什么适当的操作?我的意思是应该使用 .gif 图像,例如:http://2.bp.blogspot.com/-O7nsXfmgwSc/T6PQ0PVr6-I/AAAAAAAAAQI/-eXkEXj24-s/s1600/02.gif,如果是这样,条的前景色会在过程中填充图像文件吗?有没有办法为酒吧的背景创建动画?我的目标是在该过程不覆盖整个栏时显示动画。

【问题讨论】:

    标签: android animation progress-bar


    【解决方案1】:

    您需要将所有这些 gif 帧图像单独获取,然后设置到 xml 文件中的动画列表中。

    这是您的 anim_progress.xml 文件代码

    <?xml version="1.0" encoding="utf-8"?>
    <animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
        android:oneshot="false">
        <item android:drawable="@drawable/i1" android:duration="500" />
        <item android:drawable="@drawable/i2" android:duration="500" />
        <item android:drawable="@drawable/i3" android:duration="500" />
        <item android:drawable="@drawable/i4" android:duration="500" />
        <item android:drawable="@drawable/i5" android:duration="500" />
        <item android:drawable="@drawable/i6" android:duration="500" />
        <item android:drawable="@drawable/i7" android:duration="500" />
        <item android:drawable="@drawable/i8" android:duration="500" />
    </animation-list>
    

    将变化的持续时间设置为平滑效果,以提供像 gif 这样的动画图像

    这里是使用这个文件的代码

    ImageView iv = new ImageView(this);
    iv.setBackgroundResource(R.drawable.anim_progress);
    final AnimationDrawable mailAnimation = (AnimationDrawable) iv.getBackground();
    iv.post(new Runnable() {
        public void run() {
            if ( mailAnimation != null ) mailAnimation.start();
          }
    });
    

    setContentView(iv);

    您可以从本站的 gif 文件中获取所有帧。

    http://gif-explode.com/

    例如

    http://2.bp.blogspot.com/-O7nsXfmgwSc/T6PQ0PVr6-I/AAAAAAAAAQI/-eXkEXj24-s/s1600/02.gif

    这个链接只是传递它,你会得到所有的帧图像

    【讨论】:

    • 非常感谢,我正在尝试,会通知您!
    • 知道如何将 ImageView 设置为进度条的背景吗?
    • 设置进度条的背景。 Imageview 无法将设置背景设置为另一个视图,但您可以使用相对布局将背景设置为另一个视图
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-02
    • 2017-10-12
    • 2010-10-23
    • 1970-01-01
    • 2011-02-06
    • 2017-11-10
    相关资源
    最近更新 更多