SoFunction
Updated on 2025-03-01

Android implements multiple image synthesis loading animation

This article shares the specific code for Android to implement multiple image synthesis and load animations for your reference. The specific content is as follows

1. Customize ProgressDialog

public class MyProgressDialog extends ProgressDialog {
    private int procressLoadRes;
    private ImageView mImageView;
    private AnimationDrawable animationDrawable;

    public MyProgressDialog(Context context,int procressLoadRes) {
        super(context);
         = procressLoadRes;
    }

    public MyProgressDialog(Context context, int theme, int procressLoadRes) {
        super(context, theme);
         = procressLoadRes;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        (savedInstanceState);
        setContentView(.layout_progress);
        mImageView = (ImageView) findViewById();
        //Set animation background        (procressLoadRes);
        //Get the animation object, it must be after the previous step        animationDrawable = (AnimationDrawable) ();
        (new Runnable() {
            @Override
            public void run() {
                //Start the animation                ();
            }
        });
    }
}

2. Layout_progress.xml corresponding to MyProgressDialog

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:andro
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:background="@null">

    <ImageView
        android:
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

3. Use a custom MyProgressDialog

public class MainActivity extends AppCompatActivity {

    private Button button;
    private MyProgressDialog progressDialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        (savedInstanceState);
        setContentView(.activity_main);
        button = (Button) findViewById();
        //Pass in style and anim files        progressDialog = new MyProgressDialog(this,,);

        (new () {
            @Override
            public void onClick(View view) {
                ();
            }
        });
    }
}

4. When using it, you need a style file and anim file.

&lt;style name="dialog" parent="@android:style/"&gt;
        &lt;!--frame--&gt;
        &lt;item name="android:windowFrame"&gt;@null&lt;/item&gt;
        &lt;!--Does it appearactivityAbove--&gt;
        &lt;item name="android:windowIsFloating"&gt;true&lt;/item&gt;
        &lt;!--translucent--&gt;
        &lt;item name="android:windowIsTranslucent"&gt;false&lt;/item&gt;
        &lt;!--Untitled--&gt;
        &lt;item name="android:windowNoTitle"&gt;true&lt;/item&gt;
        &lt;!--背景透明去掉背景色frame也就去掉了 --&gt;
        &lt;item name="android:windowBackground"&gt;@color/transparent&lt;/item&gt; 
        &lt;!--Vague--&gt;
        &lt;item name="android:backgroundDimEnabled"&gt;false&lt;/item&gt;
    &lt;/style&gt;

Files under anim folder

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:andro>
    <item android:drawable="@mipmap/loading1" android:duration="100"/>
    <item android:drawable="@mipmap/loading2" android:duration="100"/>
    <item android:drawable="@mipmap/loading3" android:duration="100"/>
    <item android:drawable="@mipmap/loading4" android:duration="100"/>
    <item android:drawable="@mipmap/loading5" android:duration="100"/>
    <item android:drawable="@mipmap/loading6" android:duration="100"/>
    <item android:drawable="@mipmap/loading7" android:duration="100"/>
    <item android:drawable="@mipmap/loading8" android:duration="100"/>
    <item android:drawable="@mipmap/loading9" android:duration="100"/>
    <item android:drawable="@mipmap/loading10" android:duration="100"/>
    <item android:drawable="@mipmap/loading11" android:duration="100"/>
    <item android:drawable="@mipmap/loading12" android:duration="100"/>
    <item android:drawable="@mipmap/loading13" android:duration="100"/>
    <item android:drawable="@mipmap/loading14" android:duration="100"/>
    <item android:drawable="@mipmap/loading15" android:duration="100"/>
    <item android:drawable="@mipmap/loading16" android:duration="100"/>
    <item android:drawable="@mipmap/loading17" android:duration="100"/>
    <item android:drawable="@mipmap/loading18" android:duration="100"/>
    <item android:drawable="@mipmap/loading19" android:duration="100"/>
    <item android:drawable="@mipmap/loading20" android:duration="100"/>
    <item android:drawable="@mipmap/loading21" android:duration="100"/>
    <item android:drawable="@mipmap/loading22" android:duration="100"/>
    <item android:drawable="@mipmap/loading23" android:duration="100"/>
    <item android:drawable="@mipmap/loading24" android:duration="100"/>
    <item android:drawable="@mipmap/loading25" android:duration="100"/>
    <item android:drawable="@mipmap/loading26" android:duration="100"/>
    <item android:drawable="@mipmap/loading27" android:duration="100"/>
    <item android:drawable="@mipmap/loading30" android:duration="100"/>
    <item android:drawable="@mipmap/loading31" android:duration="100"/>
    <item android:drawable="@mipmap/loading32" android:duration="100"/>
    <item android:drawable="@mipmap/loading33" android:duration="100"/>
    <item android:drawable="@mipmap/loading34" android:duration="100"/>
</animation-list>

Add in file

<color name="transparent">#00ffffff</color>

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.