简介:补间动画:做flash动画时,在两个关键帧中间需要做“补间动画”,才能实现图画的运动;插入补间动画后两个关键帧之间的插补帧是由计算机自动运算而得到的。(来自百度百科)

demo

1布局

<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"android:orientation="vertical"tools:context=".MainActivity" ><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:orientation="horizontal" ><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="click1"android:text="透明度" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="click2"android:text="缩放" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="click3"android:text="旋转" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="click4"android:text="平移" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:onClick="click5"android:text="组合" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center" ><ImageViewandroid:id="@+id/iv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/ic_launcher" /></LinearLayout></LinearLayout>

2Mainactivity

package com.example.a112tweenanimation;import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;public class MainActivity extends Activity {private ImageView iv;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);iv = (ImageView) findViewById(R.id.iv);}/*** 透明度变化*/public void click1(View view) {// para 开始透明度 结束透明度AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);// 动画播放5秒animation.setDuration(5000);// 重复播放两次 2+1=3animation.setRepeatCount(2);// 反向变化animation.setRepeatMode(Animation.REVERSE);iv.startAnimation(animation);}/*** 缩放*/public void click2(View view) {// paras 1开始水平缩放比例 2放大到几倍 3开始垂直缩放比例 4放大到几倍 5x坐标类型RELATIVE_TO_SELF相对于自身// 6缩放时以那个位置为中心缩放 0.5f控件中心 7,8与五六类似ScaleAnimation animation = new ScaleAnimation(0.2f, 2.0f, 0.2f, 2.0f,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);// 动画播放5秒animation.setDuration(5000);// 重复播放两次 2+1=3animation.setRepeatCount(2);// 反向变化animation.setRepeatMode(Animation.REVERSE);iv.startAnimation(animation);}/*** 旋转*/public void click3(View view) {// paras 1fromDegrees从什么角度旋转 2toDegrees旋转多少度 3pivotXType 4pivotXValue// 5pivotYType 6pivotYValue 3-6参数指定旋转中心RotateAnimation animation = new RotateAnimation(0, 360,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);// 动画播放5秒animation.setDuration(5000);// 重复播放两次 2+1=3animation.setRepeatCount(2);// 反向变化animation.setRepeatMode(Animation.REVERSE);iv.startAnimation(animation);}/*** 平移*/public void click4(View view) {// paras 1fromXType水平相当于谁平移 2fromXValue水平初始位置 3toXType 4toXValue// 参数3,4:移动后的位置 5fromYValue 6fromYValue 7toYType 8toYValue 与1234类似// 只是是y方向TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,Animation.RELATIVE_TO_PARENT, 1.0f,Animation.RELATIVE_TO_PARENT, 0.0f,Animation.RELATIVE_TO_PARENT, 1.0f);// 动画播放5秒animation.setDuration(5000);// 重复播放两次 2+1=3animation.setRepeatCount(2);// 反向变化animation.setRepeatMode(Animation.REVERSE);iv.startAnimation(animation);}/*** 组合动画*/public void click5(View view) {//参数动画变化速率AnimationSet set = new AnimationSet(false);TranslateAnimation ta = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,Animation.RELATIVE_TO_PARENT, 1.0f,Animation.RELATIVE_TO_PARENT, 0.0f,Animation.RELATIVE_TO_PARENT, 1.0f);// 动画播放5秒ta.setDuration(5000);// 重复播放两次 2+1=3ta.setRepeatCount(2);// 反向变化ta.setRepeatMode(Animation.REVERSE);RotateAnimation ra = new RotateAnimation(0, 360,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);// 动画播放5秒ra.setDuration(5000);// 重复播放两次 2+1=3ra.setRepeatCount(2);// 反向变化ra.setRepeatMode(Animation.REVERSE);ScaleAnimation sa = new ScaleAnimation(0.2f, 2.0f, 0.2f, 2.0f,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);// 动画播放5秒sa.setDuration(5000);// 重复播放两次 2+1=3sa.setRepeatCount(2);// 反向变化sa.setRepeatMode(Animation.REVERSE);set.addAnimation(sa);set.addAnimation(ra);set.addAnimation(ta);iv.startAnimation(set);}
}

Android笔记 动画之tween(补间)动画demo相关推荐

  1. 安卓学习笔记32:实现补间动画

    文章目录 零.学习目标 一.安卓实现动画的三种方式 1.补间动画(tween animation) 2.帧式动画(frame animation) 3.属性动画(property animation) ...

  2. Android动画学习记录一(Android动画种类、补间动画和帧动画)

    Android动画学习记录一(动画种类.补间动画和帧动画) 动画种类.补间动画和帧动画 Android动画学习记录一(动画种类.补间动画和帧动画) 一.动画种类 二.View动画 2.1 补间动画 补 ...

  3. 形状补间动画和动作补间动画区别一览表

    形状补间动画和动作补间动画区别一览表 项目 形状补间动画 动作补间动画 概念 在一个关键帧中绘制一个形状,然后在另外一个关键帧更改或绘制另一个形状,FLASH据二者间形状创建的动画 在一个关键帧中设置 ...

  4. Android动画学习之补间动画和逐帧动画,移动互联网app开发

    | fromXScale | 指定动画开始时X轴上的缩放系数 | 值为1.0表示不再变化 | | fromYScale | 指定动画开始时Y轴上的缩放系数 | 值为1.0表示不再变化 | | toXS ...

  5. Android动画学习之补间动画

    补间动画简介 补间动画指的是做FLASH动画时,在两个关键帧中间需要做"补间动画",才能实现图画的运动:插入补间动画后两个关键帧之间的插补帧是由计算机自动运算而得到的. 补间动画分 ...

  6. Android实现蝴蝶动画,蝴蝶飞舞- (补间动画+逐帧动画)

    AnimationDrawable animationDrawable; //逐帧动画 //移动蝴蝶位置的定时器 Timer tmrTranslate; TimerTask timerTask; Im ...

  7. android 补间动画有停顿,Android动画原理分析(一)----补间动画

    1.基本特点 补间动画(Tween动画),是android最早的动画框架,从Android1.0开始就有. 功能:可以实现移动.旋转.缩放.渐变四种效果以及这四种效果的组合形式. 实现形式:xml和代 ...

  8. Android动画总结系列(2)——补间动画使用

    一.综述 补间动画(Tween Animation.View Animation)是Android的基本动画之一,其与帧动画的本质完全不同.帧动画的原理是逐帧播放Drawable形成动画效果,补间动画 ...

  9. Android补间动画

    概述 本篇博客基于<Android开发艺术探索>,将会介绍以下两种动画: 补间动画 帧动画 事实上帧动画也是补间动画的一种,但是它们的使用方式略有不同,所以将它们分开介绍. 一.补间动画 ...

  10. android 帧动画张数限制,Android帧动画和补间动画看这篇足够了

    原标题:Android帧动画和补间动画看这篇足够了 写在前面 为了使用户的交互更加流畅自然,动画也就成为了一个应用中必不可少的元素之一.在 Android 中常用的动画分类无外乎三种,最早的帧动画.补 ...

最新文章

  1. AFN 切换BaseUrl
  2. 数据安全最佳实践案例库建设项目正式启动
  3. 神经拟态芯片拉近AI与人脑距离
  4. linux dhclient 与 service network restart
  5. 李彦宏最新演讲:移动互联网的时代已经结束了
  6. 利用stat命令获取Linux文件系统和文件的详细状态信息
  7. html浮动代码_清除浮动与 BFC(块级格式化上下文)
  8. python中浅拷贝和深度拷贝的区别
  9. python中函数的参数传递
  10. C#:JObject、JArray、JProperty、JValue作用
  11. SpringMVC结合ajaxfileupload文件无刷新上传
  12. nagios监控php使用情况,给nagios增加监控当前php进程数的插件,并用pnp出图
  13. ZZULIOJ.1101: 逆序数字(函数专题)
  14. word自带公式编辑_如何在word自带的公式编辑器中设置字体格式
  15. ①ESP8266-wifi模块使用方法
  16. WinAPI WinMain函数
  17. [Python人工智能] 十九.Keras搭建循环神经网络分类案例及RNN原理详解
  18. DeepStream初步学习
  19. Centos7部署kubernetes集群CA证书创建和分发(二)
  20. 4K动态视频壁纸「Dynamic Wallpaper」

热门文章

  1. Qt Quick QMl学习笔记 之图片浏览器
  2. loc与iloc函数的使用
  3. AT649 自由研究
  4. Permission denied (publickey).
  5. scanf可以输入负数吗_C语言进行数据的多输入多输出
  6. 广度优先搜索(BFS)——抓住那头牛(POJ 4001)
  7. linux 7 远程桌面xrdp,[转帖]CentOS7安装xrdp(windows远程桌面连接linux)
  8. bool c语言_C语言面试54题
  9. python小型登录系统_python实现用户登录系统
  10. 【连载】如何掌握openGauss数据库核心技术?秘诀三:拿捏存储技术(6)