Background animation image on ProgressBar on Android?

后端 未结 1 560
灰色年华
灰色年华 2021-02-09 02:54

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/-O7nsXfmg

相关标签:
1条回答
  • 2021-02-09 03:26

    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

    0 讨论(0)
提交回复
热议问题