帧动画代码实现
来源:互联网 发布:看完就毁软件 编辑:程序博客网 时间:2024/06/13 02:00
package com.example.day06_code;
import android.os.Bundle;
import android.app.Activity;
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 imageView;@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView = (ImageView) findViewById(R.id.imageView);}// 透明public void alpha(View v) { AlphaAnimation animation = new AlphaAnimation(0f, 1.5f); // 持续时间 animation.setDuration(2000); // 设置重复次数 animation.setRepeatCount(2); // 重复的模式 animation.setRepeatMode(Animation.REVERSE); imageView.startAnimation(animation);}// 缩放public void scale(View v) { // ScaleAnimation animation=new ScaleAnimation(fromX, toX, fromY, toY, // pivotXType, pivotXValue, pivotYType, pivotYValue) ScaleAnimation animation = new ScaleAnimation( 1.0f, 2.0f, 1.0f, 2.0f, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f); // 持续时间 animation.setDuration(2000); // 设置重复次数 animation.setRepeatCount(2); // 重复的模式 animation.setRepeatMode(Animation.REVERSE); // 运行完的保持状态 animation.setFillAfter(true); imageView.startAnimation(animation);}// 位移public void translate(View v) { // TranslateAnimation animation=new TranslateAnimation( // fromXType, fromXValue, toXType, toXValue, fromYType, fromYValue, // toYType, toYValue) // 前四个参数都是设置x轴,后四个参数都是设置y轴 // 参数一:x轴起始点的类型(相对于自己,相对于父亲,绝对点)参数二:x轴起始点(当相对于自己和相对于父亲,都是倍数关系,当相对类型是绝对点时,代表的是像素); // 参数三:x轴终点的类型,参数四:x轴终点的位置 TranslateAnimation animation = new TranslateAnimation( Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 2, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0); // 持续时间 animation.setDuration(2000); // 设置重复次数 animation.setRepeatCount(2); // 重复的模式 animation.setRepeatMode(Animation.REVERSE); // 运行完的保持状态 animation.setFillAfter(true); imageView.startAnimation(animation);}// 旋转public void rotate(View v) { // 参数一:起始角度 // 参数二:结束角度 // 参数三:x轴原点的相对类型 // 参数四:x轴原点的位置 // 参数五:y轴原点的相对类型 // 参数六:y轴原点的位置 // 使用相对位置时,位置都倍数关系 RotateAnimation animation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); // 持续时间 animation.setDuration(2000); // 设置重复次数 animation.setRepeatCount(2); // 重复的模式 animation.setRepeatMode(Animation.REVERSE); // 运行完的保持状态 animation.setFillAfter(true); imageView.startAnimation(animation);}// 集合public void set(View v) { AnimationSet animationSet = new AnimationSet(false); // /////////////////////渐变//////////////////////////////////////////// AlphaAnimation alphaAnimation = new AlphaAnimation(0f, 1.5f); // 持续时间 alphaAnimation.setDuration(2000); // 设置重复次数 alphaAnimation.setRepeatCount(2); // 重复的模式 alphaAnimation.setRepeatMode(Animation.REVERSE); // /////////////////////放缩//////////////////////////////////////////////// ScaleAnimation scaleAnimation = new ScaleAnimation( 1.0f, 2.0f, 1.0f, 2.0f, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f); // 持续时间 scaleAnimation.setDuration(2000); // 设置重复次数 scaleAnimation.setRepeatCount(2); // 重复的模式 scaleAnimation.setRepeatMode(Animation.REVERSE); // 运行完的保持状态 scaleAnimation.setFillAfter(true); // //////////位移///////////// TranslateAnimation translateAnimation = new TranslateAnimation( Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 2, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0); // 持续时间 translateAnimation.setDuration(2000); // 设置重复次数 translateAnimation.setRepeatCount(2); // 重复的模式 translateAnimation.setRepeatMode(Animation.REVERSE); // 运行完的保持状态 translateAnimation.setFillAfter(true); // ///////旋转////// RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); // 持续时间 rotateAnimation.setDuration(2000); // 设置重复次数 rotateAnimation.setRepeatCount(2); // 重复的模式 rotateAnimation.setRepeatMode(Animation.REVERSE); // 运行完的保持状态 rotateAnimation.setFillAfter(true); //添加动画到动画集合 animationSet.addAnimation(alphaAnimation); animationSet.addAnimation(scaleAnimation); animationSet.addAnimation(translateAnimation); animationSet.addAnimation(rotateAnimation); imageView.startAnimation(animationSet);}
}
0 0
- 帧动画代码实现
- 帧动画代码实现
- java代码实现的帧动画
- android 动画代码实现
- 代码实现组合动画
- 安卓动画代码实现
- JavaScript实现动画计时器代码!!!
- 代码实现补间动画
- 补间动画代码实现
- 【Android 基础】Animation 动画介绍和实现【帧动画和Tween动画【在代码和xml中实现】】
- Unity-基于NGUI下的序列帧动画代码实现
- Android GridView实现动画效果实现代码
- Unity 代码帧动画
- android动画效果之Animations(代码实现动画)
- Android动画Animation之Tween用代码实现动画效果
- 笔记之android 动画1 用代码来实现动画
- FLEX: 代码实现图片文字动画效果
- 实现 CALayer 层动画点击的代码
- JSONArray JSONObjec
- linux内核编译 menuconfig详解
- Servlet详解
- oracle存储过程和oracle函数demo
- 【PAT甲级】【C】1002. A+B for Polynomials (25)
- 帧动画代码实现
- 路径
- 分布式搜索elasticsearch 索引文档的增删改查 入门
- 回溯算法
- NoSQL的三大基石(CAP、BASE和最终一致性)
- iOS备忘录之Git命令
- 法国潜艇制造商DCNS集团的2万多页“鲉鱼级”潜艇机密文件遭泄漏
- centos下 升级git
- 爬虫入门--按关键字爬取网络图片