设为首页 加入收藏

TOP

Android中TweenAnimation四种动画切换效果(一)
2014-11-24 03:14:24 来源: 作者: 【 】 浏览:6
Tags:Android TweenAnimation 动画 切换 效果

点击每个按钮都会有对应的动画显示


Android中TweenAnimation四种动画切换效果


activity代码:


package com.tmacsky;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.ImageView;
public class AnimationDemoActivity extends Activity {
private ImageView imageView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//定义四个动画的button属性
imageView = (ImageView)findViewById(R.id.imageView);
Button alpha = (Button)findViewById(R.id.Alpha);
alpha.setOnClickListener(new AnimationClickListener(AnimationType.Alpha));
Button rotate = (Button)findViewById(R.id.Rotate);
rotate.setOnClickListener(new AnimationClickListener(AnimationType.Rotate));
Button scale = (Button)findViewById(R.id.Scale);
scale.setOnClickListener(new AnimationClickListener(AnimationType.Scale));
Button translate = (Button)findViewById(R.id.Translate);
translate.setOnClickListener(new AnimationClickListener(AnimationType.Translate));
Button complex = (Button)findViewById(R.id.Complex);
complex.setOnClickListener(new AnimationClickListener(AnimationType.Complex));
}
//定义animationType属性
enum AnimationType{
Alpha,
Rotate,
Scale,
Translate,
Complex
}
//定义一个函数
class AnimationClickListener implements OnClickListener{
private AnimationType animationType;
public AnimationClickListener(AnimationType animType){
animationType = animType;
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (animationType) {
case Alpha:
//定义渐变动画,重复5次,持续1分钟
/*AlphaAnimation _animation = new AlphaAnimation(1f, 0.1f);
_animation.setDuration(3000);
_animation.setRepeatCount(5);
//设置循环
_animation.setRepeatMode(Animation.REVERSE);
_animation.setAnimationListener(new AnimationListener() {
//设置animation监听,依次是启动,重复,然后结束
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
Log.i("log", "animation Start");
}
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
Log.i("log", "animation Repeat");
}
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
Log.i("log", "animation End");
}
});
//启动动画
imageView.startAnimation(_animation);*/
AlphaAnimation alphaAnimation = (AlphaAnimation)AnimationUtils.loadAnimation(AnimationDemoActivity.this, R.anim.alpha);
imageView.startAnimation(alphaAnimation);
break;
case Rotate:
//定义旋转动画,旋转一周持续1分钟,重复三次,在物体的中心位置
RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux下shell编程常用grep\awk\se.. 下一篇如何让Android应用支持多种语言

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·哈希表 - 菜鸟教程 (2025-12-24 20:18:55)
·MySQL存储引擎InnoDB (2025-12-24 20:18:53)
·索引堆及其优化 - 菜 (2025-12-24 20:18:50)
·Shell 中各种括号的 (2025-12-24 19:50:39)
·Shell 变量 - 菜鸟教 (2025-12-24 19:50:37)