Android自定义一个简单的动画加载页面

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....分别为你要播放的图片


  <? xml version="1.0" encoding="utf-8" ?>
-<!--
   
    根标签为animation-list,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画  
    根标签下,通过item标签对动画中的每一个图片进行声明  
    android:duration 表示展示所用的该图片的时间长度  
 
  -->
- < animation-list xmlns:android =" http://schemas.android.com/apk/res/android " android:oneshot =" false " >
  < item android:drawable =" @drawable/w1 " android:duration =" 150 " />
  < item android:drawable =" @drawable/w2 " android:duration =" 150 " />
  < item android:drawable =" @drawable/w3 " android:duration =" 150 " />
  < item android:drawable =" @drawable/w4 " android:duration =" 150 " />
  </ animation-list >



第二步就是在布局文件中声明他

<ImageView
           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"/>


最后第三步在代码中初始化它

 ImageView imageView= (ImageView) loadview.findViewById(R.id.loading_iv);
        AnimationDrawable drawable= (AnimationDrawable) imageView.getBackground();
        drawable.setOneShot(false);
        drawable.start();



就这样能简单实现两个动画页面了


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值