帧动画
来源:互联网 发布:linux 云硬盘 挂载 编辑:程序博客网 时间:2024/06/03 12:50
实现一个等待加载动画
步骤:
1、res下创建一个anim目录 新建动画xml文件
2、将需要播放动画的控件src设置为添加的动画文件
3、AnimationDrawable 获取动画资源、加载到需要播放动画的控件上
4、控制动画的播放和停止
代码如下:
1、res下创建一个anim目录 新建动画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/loading_01" android:duration="200"/> <item android:drawable="@drawable/loading_02" android:duration="200"/> <item android:drawable="@drawable/loading_03" android:duration="200"/> <item android:drawable="@drawable/loading_04" android:duration="200"/> <item android:drawable="@drawable/loading_05" android:duration="200"/> <item android:drawable="@drawable/loading_06" android:duration="200"/> <item android:drawable="@drawable/loading_07" android:duration="200"/> <item android:drawable="@drawable/loading_08" android:duration="200"/> <item android:drawable="@drawable/loading_09" android:duration="200"/> <item android:drawable="@drawable/loading_10" android:duration="200"/> <item android:drawable="@drawable/loading_11" android:duration="200"/> <item android:drawable="@drawable/loading_12" android:duration="200"/></animation-list>2、将需要播放动画的控件src设置为添加的动画文件
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.leixiansheng.myprogressbar.MainActivity"> <ImageView android:id="@+id/image_view" android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/image_pgbar" /></RelativeLayout>3、4、AnimationDrawable 获取动画资源、加载到需要播放动画的控件上
package com.leixiansheng.myprogressbar;import android.graphics.drawable.AnimationDrawable;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.ImageView;/** * 自定义progressbar ,animationDrawable动画代替 * postDelayed :view自带handler, postDelayed 延时发送到主线程handler处理 */public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ImageView imageView = (ImageView) findViewById(R.id.image_view);// imageView.setImageResource(R.drawable.image_pgbar); //java 实现动画资源添加(也可以直接在xml中设置src添加资源) final AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getDrawable(); /** * 开始动画 */ imageView.postDelayed(new Runnable() { @Override public void run() { animationDrawable.start(); } }, 100); /** * 取消动画, */ imageView.postDelayed(new Runnable() { @Override public void run() { animationDrawable.stop(); imageView.setVisibility(View.GONE); } }, 5000); }}
阅读全文
0 0
- 动画__帧动画
- 转场动画 帧动画
- 动画 AnimationDrawable 帧动画
- 动画----帧动画
- 安卓补间动画、帧动画
- Android动画-帧动画
- Android动画--帧动画
- egret_gif动画(帧动画)
- android动画 -- 帧动画 补间动画
- 属性动画,补间动画,帧动画
- View动画、帧动画、属性动画
- Android动画-帧动画&补间动画
- Android加载动画 旋转动画 、帧动画
- 帧动画、补间动画、属性动画
- 动画(过渡动画、关键帧动画)
- Android动画-帧动画-属性动画
- 帧动画&补间动画&属性动画
- 安卓 动画帧动画基础动画
- 闭包初步感受
- FFmpeg hardware GUP codec
- 新手看不懂电路图?赶快把这份电路符号大全收藏起来吧!
- Android存储、上传、下载
- 验证表单是否正确——不能为空
- 帧动画
- 回访管理系统
- Codeforce 792B Counting-out Rhyme
- Tomcat配置通过域名访问该项目
- 软件测试学习笔记_软件测试的基本概念
- CascadeType级联关系
- java 策略设计模式
- 先码后看 Tomcat是怎么启动容器的——Lifecycle篇 侵立删
- HDFS HA以及Federation,Zookeeper概述