Android Frame动画demo
Android动画介绍:Android为我们提供了两种动画实现,Frame和Tween。
两者之间的区别:
1.Frame动画:就像放电影一样,是通过预先做好的图片进行连续播放从而形成动画效果
2.Tween动画:通过对图片设置平移、缩放、旋转、改变透明度等方式来显示动画效果
本节仅讲Frame动画,
Frame动画是通过AnimationDrawable来实现的,它提供了start()和stop()两个方法,对播放的动画进行控制,一般通过XML文件配置,在工程的res/anim目录下创建一个XML配置文件,该配置文件有一个<animation-list>根元素和若干个<item>子元素。
废话就不说了,下面将贴出该例子的完整代码,供大家测试使用:
一、FrameActivity
package com.yw.myapiupdate.frame; import com.yw.myapiupdate.R; import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView; /**
*
* 实现动画轮询播放
* @author yw-tony
*
*/
public class FrameActivity extends Activity implements OnClickListener{
private Button btn_start;
private Button btn_end;
private ImageView iv;
private AnimationDrawable ad;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.frame_layout);
initViews();
}
private void initViews(){
btn_start = (Button)findViewById(R.id.frame_btn_start);
btn_end = (Button)findViewById(R.id.frame_btn_end);
iv = (ImageView)findViewById(R.id.frame_iv);
btn_start.setOnClickListener(this);
btn_end.setOnClickListener(this);
this.ad = (AnimationDrawable)iv.getBackground();
}
private void startAnimation(){
this.ad.start();
}
private void stopAnimation(){
this.ad.stop();
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.frame_btn_start:
startAnimation();
break;
case R.id.frame_btn_end:
stopAnimation();
break;
}
}
}
与之对应的xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/frame_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@anim/framedrawable"/>
<Button
android:id="@+id/frame_btn_start"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="start"/>
<Button
android:id="@+id/frame_btn_end"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="end"/>
</LinearLayout>
二、设置动画的xml文件
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:apk="http://schemas.android.com/apk/res/android" apk:oneshot="false">
<item apk:drawable="@drawable/anim_1" apk:duration="200" />
<item apk:drawable="@drawable/anim_2" apk:duration="200" />
<item apk:drawable="@drawable/anim_3" apk:duration="200" />
<item apk:drawable="@drawable/anim_4" apk:duration="200" />
<item apk:drawable="@drawable/anim_5" apk:duration="200" />
<item apk:drawable="@drawable/anim_6" apk:duration="200" />
</animation-list>
下面是源代码以及资源文件的下载地址:
http://files.cnblogs.com/tony-yang-flutter/anni.zip
Android Frame动画demo的更多相关文章
- Android Animation 动画Demo(Frame帧动画)
上一页介绍Animation动画第一:Tween吐温动画. 本文介绍了以下Animation也有动画的形式:Frame帧动画. Frame动画是一系列照片示出的顺序按照一定的处理,和机制,以放电影很阶 ...
- android之frame动画详解
上一篇我们说了android中的tween动画,这一篇我们说说frame动画,frame动画主要是实现了一种类似于gif动画的效果,就是多张图按预先设定好的时间依次连续显示. 新建一个android项 ...
- 我的Android进阶之旅------>Android之动画之Frame Animation实例
============================首先看看官网上关于Frame animation的介绍================================ 地址:http://de ...
- Android 动画具体解释Frame动画 (Drawable Animation)
Frame动画像gif画画,通过一些静态的图片,以实现动画效果. Android sdk该AnimationDrawable就是专门针对Frame动画,当然Frame动画也可在java代码或者xml中 ...
- android 自定义动画
android自定义动画注意是继承Animation,重写里面的initialize和applyTransformation,在initialize方法做一些初始化的工作,在applyTransfor ...
- Frame动画实战
Android动画分为Tween动画和Frame动画,Tween动画主要包括图片的放大缩小.旋转.透明度变化.移动等等操作:Frame动画则简单得多了,就是把一张张的图片连续播放产生动画效果. 本节主 ...
- 79.Android之动画基础
转载:http://a.codekk.com/detail/Android/lightSky/%E5%85%AC%E5%85%B1%E6%8A%80%E6%9C%AF%E7%82%B9%E4%B9%8 ...
- Android的动画
一.动画类型 Android的animation由四种类型组成:alpha.scale.translate.rotate XML配置文件中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画 ...
- Android View动画
Animation TypeEvaluator View的animate方法 ValueAnimator ObjectAnimator AnimatorSet 使用xml来创建动画 animation ...
随机推荐
- HDU1029(KB12-B)
Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K ( ...
- DouPHP去除Powered by DouPHP版权的方法
DouPHP标题版权修改:打开 include 目录下的 action.class.php 文件,搜索“Powered”找到下面一行代码: $page_title = ($titles ? $titl ...
- PHPCMS V9开发文档
内容模块 内容模块PC标签调用说明 模块名:content 模块提供的可用操作 操作名 说明 lists 内容数据列表 relation 内容相关文章 hits 内容数据点击排行榜 category ...
- Monkey Android app稳定性测试工具之Monkey使用教程
Monkey Android app稳定性测试工具之Monkey使用教程 by:授客 QQ:1033553122 由于篇幅问题,仅提供百度网盘下载链接: Android app稳定性测试工具之Monk ...
- 单元测试(四)-隔离框架NSubstitute
之前学习了单元测试的基础知识,以及桩对象和模拟对象的不同作用.但在实际应用中,往往不会直接手写桩对象或者模拟对象,而是使用隔离框架动态的创建这些对象,这可以让测试变得更简便.快捷,还可以更好地应对复杂 ...
- chrome浏览器使用chrome://inspect调试app 网页,打开空白的问题
使用chrome浏览器,输入chrome://inspect可以调试android app里面的网页,如果inspect的时候,是空白, 问题截图: 那就在C:\Windows\System32\dr ...
- SublimeText3常用插件及快捷键总结
SublimeText可谓是前端工程师的代码编辑神器,自从用上它以后一直爱不释手,特别是它强大的插件功能,简直要逆天了.网上也有很多关于SublimeText3的各种插件介绍,其插件功能之多,让人眼花 ...
- 国内使用kubeadm部署kubernetes的完整流程
使用阿里云的镜像安装kubeadm和kubectl cat <<EOF > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Ku ...
- 重学C语言---03数据和C
1.数据的必要性.数据使我们生活中不可缺少的东西,程序也是如次,离不开数据.将文字.图片和单词等输入到算计,将其展现出来或者做一系列操作等. 2.实例程序. /*rhodium.c--用金属铑衡量体重 ...
- bootstrap使用基础
1.为了适应跨屏浏览,Bootstrap为单元格预定义了4种class ,分别对应于手机.ipad.笔记本电脑.台式机. <div class="row"> <d ...