android中提供了几种方法给我们提供一些动画页面的实现
下面来看看代码:
首先在drawable文件夹下面建一个文件,名字随便,我的示例为load.xml,代码如下
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0"
android:toDegrees="1440">
<shape android:shape="ring" android:innerRadiusRatio="3"
android:thicknessRatio="8" android:useLevel="false">
<gradient android:type="sweep" android:useLevel="false"
android:startColor="#FFFFFF" android:centerColor="@color/dodgerblue"
android:centerY="0.50" android:endColor="@color/blue" />
</shape>
</rotate>
然后再到布局文件使用它
<ProgressBar
android:id="@+id/loading_process_dialog_progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="false"
android:indeterminateDrawable="@drawable/load" />
这样布局运行之后就会在手机显示一个圆形条转动的动画效果。
还有第二种实现方式就是播放图片的帧动画:
实现步骤是:首先在anim文件夹下面建立一个loading_anima.xml文件 w1、w2....分别为你要播放的图片
根标签为animation-list,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画 根标签下,通过item标签对动画中的每一个图片进行声明 android:duration 表示展示所用的该图片的时间长度-->
android:layout_centerHorizontal="true"
android:id="@+id/loading_iv"
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="fitXY"
android:background="@anim/loading_anima"/>
AnimationDrawable drawable= (AnimationDrawable) imageView.getBackground();
drawable.setOneShot(false);
drawable.start();
就这样能简单实现两个动画页面了