Android笔记 动画之tween(补间)动画demo
来源:互联网 发布:ubuntu 设置默认路径 编辑:程序博客网 时间:2024/05/22 14:17
简介:补间动画:做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" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="click1" android:text="透明度" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="click2" android:text="缩放" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="click3" android:text="旋转" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="click4" android:text="平移" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="click5" android:text="组合" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" > <ImageView android: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);}}
0 0
- Android笔记 动画之tween(补间)动画demo
- android动画之:补间动画(Tween动画)
- Android tween动画(补间动画)
- Android 动画系列之补间(Tween)动画详解
- Android动画效果之Tween Animation(补间动画)
- android 动画实现之 Tween Animation(补间动画)
- Android动画效果之Tween Animation(补间动画)
- Android 学习之补间(Tween)动画
- Android基础篇之补间动画(Tween)
- Android开发之Tween(补间动画)
- android补间动画(Tween Animation)
- android 补间(Tween)动画
- Android-Animation动画之Tween Animation补间动画
- Android动画之补间动画(Tween Animation)
- Android动画之补间动画(Tween Animation)
- Android——动画之补间动画(Tween动画)
- Android 动画--补间动画(Tween Animation)
- 补间动画(Tween)
- Ubantu12.04设置无线上网及静态地址
- libmad学习进阶2----利用libmad将mp3转码成pcm
- Android4.2蓝牙基础架构学习
- java 23 种设计模式
- pat 1070Mooncake (25)
- Android笔记 动画之tween(补间)动画demo
- IOS 实现录音PCM转MP3格式(边录音边转码)
- 王立平--图片加密
- 利用crsctl生产resource脚本,并生成新的资源
- 圆形进度条
- Gridview中的数据导出到excel中
- 条件编译
- Leetcode:Largest Rectangle in Histogram与Maximal Rectangle
- Stack和Heap