使用Animation-list实现等待旋转圆圈动画
来源:互联网 发布:php代理跨域 编辑:程序博客网 时间:2024/06/04 18:59
我们在做网络交互或是从服务器提取数据的时候,常常会给出一个等待的动画,就是一个小圆圈转啊转的。它的使用很简单,我们只要使用Animation-list用三,五行代码,就可以搞定了。
首先,我们要找几个转圈的图片,注意这几个图片是有讲究的,就是它们正好可以拼接成一个转圈的动画,如下图
这个网上有很多,大家可以自行去找一下
下面看代码,首先,建立anim文件夹,然后在里面建:imgloading.xml
<?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/black_01" android:duration="150"/> <item android:drawable="@drawable/black_02" android:duration="150"/> <item android:drawable="@drawable/black_03" android:duration="150"/> <item android:drawable="@drawable/black_04" android:duration="150"/> <item android:drawable="@drawable/black_05" android:duration="150"/> <item android:drawable="@drawable/black_06" android:duration="150"/> <item android:drawable="@drawable/black_07" android:duration="150"/> <item android:drawable="@drawable/black_08" android:duration="150"/> <item android:drawable="@drawable/black_09" android:duration="150"/> <item android:drawable="@drawable/black_10" android:duration="150"/> <item android:drawable="@drawable/black_11" android:duration="150"/> <item android:drawable="@drawable/black_12" android:duration="150"/></animation-list>
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:gravity="center"> <ImageView android:id="@+id/img_loading" android:layout_width="wrap_content" android:layout_height="wrap_content" /></LinearLayout>
程序代码:mainActivity.java
import android.graphics.drawable.AnimationDrawable;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.widget.ImageView;public class MainActivity extends AppCompatActivity { private ImageView img_loading; private AnimationDrawable AniDraw; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); img_loading = (ImageView)findViewById(R.id.img_loading); img_loading.setBackgroundResource(R.anim.imgloading); AniDraw = (AnimationDrawable)img_loading.getBackground(); AniDraw.start(); }}效果如下图:
0 2
- 使用Animation-list实现等待旋转圆圈动画
- 使用Animation-list实现等待旋转圆圈动画
- android等待旋转圆圈动画
- 使用Animation-list实现等待加载动画效果
- animation-list实现动画
- android 视图动画的使用,Animation重写 实现旋转效果
- CSS3 animation--圆圈刷新动画
- Android 使用animation-list实现逐帧动画
- 用Animation-list实现逐帧动画
- Android animation-list 实现加载动画效果
- 使用Animation实现摄像机动画
- Animation旋转的动画
- Android中补间动画1----Animation的基本使用代码实现(平移,缩放,渐变,旋转)
- 【Animation】Android 用Animation-list实现逐帧动画
- Android动画之animation-list实现逐帧动画
- Animation-list帧动画使用【微信语音播放动画】
- Animation-list帧动画使用【微信语音播放动画】
- 使用Animation list实现网络请求过程中的加载动画dialog
- Android webapp Ajax exception `INVALID_STATE_ERR: DOM Exception 11`
- Mysql学习笔记七,存储过程和函数
- jQuery ZeroClipboard粘贴板
- hibernate tools自动生成entity代码
- 漫谈设计模式--3分钟理解桥接模式:笔和画的关系
- 使用Animation-list实现等待旋转圆圈动画
- Scala学习第十七天 包、类、对象、成员、伴生类、伴生对象访问权限实战彻底详解
- hadoop2.6 & apache-hive-1.2.1-bin & pig-0.15.0 因jline不兼容
- struts2的核心和工作原理
- hibernate注解详解
- http get与post请求区别
- ES6新特性概览
- Win10正式企业版激活方法
- 混淆