首先看一下效果图:
我们要实现的就是图中动态旋转的一个加载样式图,图片资源均来自互联网,下面会附上源码。
实现该效果有很多种办法,本次要记录的时使用animation样式的progressbar来实现,既简单又美观。
首先要创建一个anim的样式文件loading.xml,单独放在anim文件夹下
<?xml version="1.0" encoding="UTF-8"?>
<animation-list android:oneshot="false"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:duration="200" android:drawable="@drawable/refresh1" />
<item android:duration="200" android:drawable="@drawable/refresh2" />
<item android:duration="200" android:drawable="@drawable/refresh3" />
<item android:duration="200" android:drawable="@drawable/refresh4" />
<item android:duration="200" android:drawable="@drawable/refresh5" />
<item android:duration="200" android:drawable="@drawable/refresh6" />
<item android:duration="200" android:drawable="@drawable/refresh7" />
<item android:duration="200" android:drawable="@drawable/refresh8" />
</animation-list>
refresh1-8代表动态切换的八张图片,每张停留的时间设为200,这个单位难道时毫秒?应该是。
xml文件建立好,要在styles文件中利用它。创建styles.xml文件,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="qZoneListProgressStyle" parent="@android:style/Widget.ProgressBar.Small">
<item name="android:indeterminateDrawable">@anim/loading</item>
</style>
</resources>
接下来只要在layout文件中添加一个progressba控件,然后style设置为我们刚刚写的style就好了。
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center"
android:orientation="horizontal"
android:id="@+id/LinearLayoutloadingfooter"
android:background="#ffebf8ff"
android:layout_width="fill_parent"
android:layout_height="60.0dip"
>
<ProgressBar
android:id="@+id/footLoading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/qZoneListProgressStyle" />
<TextView
android:textColor="@color/black"
android:id="@+id/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text ="@string/loading"
/>
</LinearLayout>
如果想要大一点的progressbar,首先要把那8张图片做的大一些,然后修改style中的内容,如下:
<style name="netdiskListProgressStyle" parent="@android:style/Widget.ProgressBar.Large">
<item name="android:indeterminateDrawable">@anim/loading</item>
</style>
最后附上源码: