android 加载数据或提交数据时显示转圈的提示页面
提前声明一下,本博客全是自己的理解,如果内容中有理解错误的地方,欢迎指正。另外,博客内容有参考其他博客,本博客只用来学习。
当我们进入到一个页面时,通常先会出现一个转圈的dialog,这是因为这个页面需要加载数据,为了防止数据加载完成前空白的页面,通常会先显示转圈的dialog,直到数据加载完成,圈消失。那么,这个转圈的dialog是怎么实现的呢?
首先,先写 显示转圈的layout:progress_hud.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/progress_hud_bg"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="20dp"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:paddingTop="20dp" >
<ImageView
android:id="@+id/spinnerImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@anim/spinner" />
<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Message"
android:textColor="#FFFFFF" />
</LinearLayout>
图片的背景是动画spinner,具体实现如下:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item
android:drawable="@drawable/spinner_0"
android:duration="60"/>
<item
android:drawable="@drawable/spinner_1"
android:duration="60"/>
<item
android:drawable="@drawable/spinner_2"
android:duration="60"/>
<item
android:drawable="@drawable/spinner_3"
android:duration="60"/>
<item
android:drawable="@drawable/spinner_4"
android:duration="60"/>
<item
android:drawable="@drawable/spinner_5"
android:duration="60"/>
<item
android:drawable="@drawable/spinner_6"
android:duration="60"/>
<item
android:drawable="@drawable/spinner_7"
android:duration="60"/>
<item
android:drawable="@drawable/spinner_8"
android:duration="60"/>
<item
android:drawable="@drawable/spinner_9"
android:duration="60"/>
<item
android:drawable="@drawable/spinner_10"
android:duration="60"/>
<item
android:drawable="@drawable/spinner_11"
android:duration="60"/>
</animation-list>
这里提一下安卓的动画。android支持3种动画模式,tween animation,frame animation和property animation,这三种动画模式在SDK中被称为view animation,drawable animation和property animation。
tween animation(view animation):补间动画。