Android动画之进度条

Android开发中在处理耗时工作的时候,例如:列表加载,大多数会有一个精度条加载的框,里面有一个像gif的图片在旋转一样。

定义res/anim/loading.xml:

<!--

    根标签为animation-list,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画   true展示一遍

    根标签下,通过item标签对动画中的每一个图片进行声明 

  android:duration 表示展示该图片的时间长度 

-->

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

 


在layout文件中引用如下:

<?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="启动"/>



        <Button

            android:id="@+id/button2"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="暂停"/>

    </LinearLayout>



</LinearLayout>

 

效果图:

 源码点击下载

猜你喜欢

转载自zhangqie.iteye.com/blog/2363868