Android animation progress bar

When dealing with time-consuming tasks in Android development, such as list loading, most of them will have a frame loaded with a precision bar, and there will be a gif-like image spinning inside.

 

Define res/anim/loading.xml:

<!--

    The root tag is animation-list, in which oneshot represents whether to display it only once. If set to false, the animation will be played in a loop. True will display it once.

    Under the root tag, declare each image in the animation through the item tag 

  android:duration indicates the length of time to display the image 

-->

 

<?xmlversion="1.0"encoding="utf-8"?>

<animation-listxmlns:android="http://schemas.android.com/apk/res/android"

    android:oneshot="false">



    <item

        android:drawable="@drawable/loading1"

        android:duration="100"/>

    <item

        android:drawable="@drawable/loading2"

        android:duration="100"/>

    <item

        android:drawable="@drawable/loading3"

        android:duration="100"/>

    <item

        android:drawable="@drawable/loading4"

        android:duration="100"/>

    <item

        android:drawable="@drawable/loading5"

        android:duration="100"/>

    <item

        android:drawable="@drawable/loading6"

        android:duration="100"/>

    <item

        android:drawable="@drawable/loading7"

        android:duration="100"/>

    <item

        android:drawable="@drawable/loading8"

        android:duration="100"/>

    <item

        android:drawable="@drawable/loading9"

        android:duration="100"/>

    <item

        android:drawable="@drawable/loading10"

        android:duration="100"/>

    <item

        android:drawable="@drawable/loading11"

        android:duration="100"/>

    <item

        android:drawable="@drawable/loading12"

        android:duration="100"/>



</animation-list>

 


The reference in the layout file is as follows:

<?xmlversion="1.0"encoding="utf-8"?>

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:background="@android:color/white"

    android:gravity="center_horizontal"

    android:orientation="vertical">



    <ProgressBar

        android:id="@+id/xlistview_footer_progressbar"

        android:layout_width="21dp"

        android:layout_height="21dp"

        android:layout_centerInParent="true"

        android:layout_marginTop="15dp"

        android:indeterminate="false"

        android:indeterminateDrawable="@anim/loading"/>



    <ImageView

        android:id="@+id/imageView1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_marginTop="50dp"/>



    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content">



        <Button

            android:id="@+id/button1"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="Start"/>



        <Button

            android:id="@+id/button2"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="pause"/>

    </LinearLayout>



</LinearLayout>

 

 

 

 

Effect picture:

 

 Source code click to download

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326377442&siteId=291194637