Background animation image on ProgressBar on Andro

2019-03-20 05:02发布

What is the appropriate action to take when you need to change the background image of a ProgressBar? I mean should use a .gif image like : http://2.bp.blogspot.com/-O7nsXfmgwSc/T6PQ0PVr6-I/AAAAAAAAAQI/-eXkEXj24-s/s1600/02.gif and if so will the foreground color of the bar fill the image file during the proccess ? Is there a way of creating an animation for the background of the bar ? What i am aiming for is to show the animation for as long the process does not cover the full bar.

1条回答
劫难
2楼-- · 2019-03-20 05:43

you need to get all this gif frame image as individual and then set into the animation-list in xml file.

Here is your anim_progress.xml file code

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

set the duration for change as smooth effect for giving animated image like gif

Here is the code for using this file

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);

you can get all frames from gif file from this site.

http://gif-explode.com/

for example

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

this link just pass it and you will get all the frame images

查看更多
登录 后发表回答