简单的四种动画Demo
来源:互联网 发布:怎样开淘宝店 编辑:程序博客网 时间:2024/04/29 16:16
package com.saiermeng.annimation;import android.app.Activity;import android.os.Bundle;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; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv = (ImageView) findViewById(R.id.iv_xfj); } public void alpha(View v){ // 创建透明度的动画对象 // fromAlpha 开始透明度的值 0~1.0 由完全透明到完全不透明 // toAlpha 结束透明度的值 AlphaAnimation aa = new AlphaAnimation(0, 1.0f); //设置动画重复播放的次数 aa.setRepeatCount(2); //设置动画播放的顺序的模式:REVERSE 相反的顺序 aa.setRepeatMode(AlphaAnimation.REVERSE); //设置动画播放的总时间长度 aa.setDuration(3000); //在IMageView上播放动画 iv.startAnimation(aa); } public void rotate(View v) { // 创建旋转的动画对象 // fromDegrees 旋转的开始角度 0~360 // toDegrees 旋转的结束角度 // pivotXType 在水平方向相对旋转的类型,如 RELATIVE_TO_SELF:相对自己,相对父级窗体 // pivotXValue 相对的位置,如自己宽度的0.5f // pivotYType 在垂直方向相对选装的类型,如 RELATIVE_TO_SELF:相对自己,相对父级窗体 // pivotYValue 相对的位置,如自己高度的0.5f RotateAnimation ra = new RotateAnimation(0, 360, 1, 0.5f, 1, 0.5f); // 设置动画重复播放的次数 ra.setRepeatCount(2); // 设置动画重复播放的顺序的模式:REVERSE 相反的顺序 ra.setRepeatMode(AlphaAnimation.REVERSE); // 设置动画重复播放的总时间长度 ra.setDuration(3000); // 在imageview上播放动画 iv.startAnimation(ra); } public void scale(View v) { // 创建缩放的动画对象 // fromX 开始缩放时宽度的比例 最小为0,放大一倍为1.0f // toX 结束缩放时宽度的比例 // fromY 开始缩放时高度开始缩放时宽度的比例 最小为0,放大一倍为1.0f // toY 结束缩放时高度的比例的比例 最小为0,放大一倍为1.0f // pivotXType 在水平方向相对缩放的类型,如 RELATIVE_TO_SELF:相对自己,相对父级窗体 // pivotXValue 相对的位置,如自己宽度的0.5f // pivotYType 在垂直方向相对缩放的类型,如 RELATIVE_TO_SELF:相对自己,相对父级窗体 // pivotYValue 相对的位置,如自己高度的0.5f ScaleAnimation sa = new ScaleAnimation(0, 2.0f, 0, 2.0f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f); // 设置动画重复播放的次数 sa.setRepeatCount(2); // 设置动画重复播放的顺序的模式:REVERSE 相反的顺序 sa.setRepeatMode(AlphaAnimation.REVERSE); // 设置动画重复播放的总时间长度 sa.setDuration(3000); // 在imageview上播放动画 iv.startAnimation(sa); } public void trans(View v) { // 创建平移的动画对象 // fromXType 在水平方向平移时相对的类型, // fromXValue 平移的开始位置 // toXType 在水平方向平移时相对的类型, // toXValue 在水平方向平移倍数 // fromYType 在垂直方向平移时相对的类型, // fromYValue 平移的开始位置 // toYType 在垂直方向平移时相对的类型, // toYValue 在垂直方向平移倍数 TranslateAnimation ta = new TranslateAnimation( TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 3.0f, TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 3.0f); // 设置动画重复播放的次数 ta.setRepeatCount(2); // 设置动画重复播放的顺序的模式:REVERSE 相反的顺序 ta.setRepeatMode(AlphaAnimation.REVERSE); // 设置动画重复播放的总时间长度 ta.setDuration(3000); // 在imageview上播放动画 iv.startAnimation(ta); } public void set(View v) { // 创建动画集合 // shareInterpolator 插筒, true 表示一个动画接一个的播放动画 false会把几种动画总到一起播放 AnimationSet set =new AnimationSet(false); AlphaAnimation aa = new AlphaAnimation(0, 1.0f); // 设置动画重复播放的次数 aa.setRepeatCount(2); // 设置动画重复播放的顺序的模式:REVERSE 相反的顺序 aa.setRepeatMode(AlphaAnimation.REVERSE); // 设置动画重复播放的总时间长度 aa.setDuration(3000); set.addAnimation(aa); RotateAnimation ra = new RotateAnimation(0, 360, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); // 设置动画重复播放的次数 ra.setRepeatCount(2); // 设置动画重复播放的顺序的模式:REVERSE 相反的顺序 ra.setRepeatMode(AlphaAnimation.REVERSE); // 设置动画重复播放的总时间长度 ra.setDuration(3000); set.addAnimation(ra); ScaleAnimation sa = new ScaleAnimation(0, 2.0f, 0, 2.0f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f); // 设置动画重复播放的次数 sa.setRepeatCount(2); // 设置动画重复播放的顺序的模式:REVERSE 相反的顺序 sa.setRepeatMode(AlphaAnimation.REVERSE); // 设置动画重复播放的总时间长度 sa.setDuration(3000); set.addAnimation(sa); TranslateAnimation ta = new TranslateAnimation( TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 3.0f, TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 3.0f); // 设置动画重复播放的次数 ta.setRepeatCount(2); // 设置动画重复播放的顺序的模式:REVERSE 相反的顺序 ta.setRepeatMode(AlphaAnimation.REVERSE); // 设置动画重复播放的总时间长度 ta.setDuration(3000); set.addAnimation(ta); iv.startAnimation(set); }}
0 0
- 简单的四种动画Demo
- Unity3D一个简单的动画混合Demo
- 基于HTML5的简单游戏动画Demo
- swift简单动画demo
- Qt 简单动画demo
- 命令模式demo-一个简单的动画回放功能
- View的四种动画,
- Android 帧动画 FrameAnimation 简单DEMO
- Android 补件动画 TweenAnimation 简单DEMO
- jquery移动动画的Demo
- 传统动画Animation的四种基础动画的使用
- 传统动画Animation的四种基础动画的使用
- 传统动画Animation的四种基础动画的使用
- Android的animation的四种动画
- Storm(四)Storm简单测试demo
- android学习-动画(基本的四种动画)
- Android 动画效果(二):四种基础动画的 **动态设置、动画监听、组合动画
- Android 四种动画效果的调用
- Windos下经典小工具介绍
- mysql常用函数
- BZOJ 3224: Tyvj 1728 普通平衡树
- Linux下的tar压缩解压缩命令详解
- linux-grep快速使用
- 简单的四种动画Demo
- 验证码小例子源码
- 要想实现留学梦想 美国本科学费与语言考试(雅思)都需提前准备
- 中文字符串日期改成英文的日期格式
- 负载均衡----实现配置篇(Nginx)
- Android百度地图,绘制,覆盖物,导航,定位,细腻分解!
- 轮播图--myFocus
- OpenBSC编译安装指南(1)-OsmoTRX
- Siege压力测试编译安装