您的位置:首页 > 移动开发 > Android开发

简单记录,关于android animation的简单应用。

2013-05-14 16:17 344 查看
findViewById(R.id.translate).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//左右晃动 or 上下晃动  or 斜着
TranslateAnimation animation = new TranslateAnimation(0,
mButton.getWidth() + x, 0, 0);
animation.setInterpolator(new CycleInterpolator(2f));
animation.setDuration(10000);
//				animation.setFillEnabled(true);  //停止动画button停在那里。
//				animation.setFillAfter(true);
//				animation.setFillBefore(true);
animation.initialize(mButton.getWidth(), mButton.getHeight(),
mButton.getWidth(), mButton.getHeight());
mButton.startAnimation(animation);
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}

@Override
public void onAnimationRepeat(Animation animation) {
}

@Override
public void onAnimationEnd(Animation animation) {
animation = new TranslateAnimation(0, mButton
.getWidth(), 0, 0);
animation.setInterpolator(new CycleInterpolator(2f));
animation.setDuration(10000);
mButton.startAnimation(animation);
}
});
}
});
findViewById(R.id.rotate).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//旋转
RotateAnimation animation = new RotateAnimation(0, 720,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(10000);
mButton.startAnimation(animation);
}
});
findViewById(R.id.scale).setOnClickListener(new OnClickListener() {
//比例放大
@Override
public void onClick(View v) {
//参数 1.开始的x轴方向比例2.结束时的x轴方向比例3.y的开始4.y的结束5.开始时的中心坐标(以自己为标准)6.以自己的水品方向的2倍坐标为中心7.y的8.自己y方向的0.5倍坐标及自己的y方向的中心点。
ScaleAnimation animation = new ScaleAnimation(0, 1f, 0, 1f,
Animation.RELATIVE_TO_SELF, 2,
Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(10000);
mButton.startAnimation(animation);
}
});
findViewById(R.id.alpha).setOnClickListener(new OnClickListener() {
//透明度
@Override
public void onClick(View v) {
AlphaAnimation alphaAnimation = new AlphaAnimation(0f, 1f);
alphaAnimation.setDuration(10000);
alphaAnimation.setRepeatCount(-1);
alphaAnimation.setRepeatMode(Animation.REVERSE);
mButton.startAnimation(alphaAnimation);
alphaAnimation.setAnimationListener(new AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {
}

@Override
public void onAnimationRepeat(Animation animation) {
}

@Override
public void onAnimationEnd(Animation animation) {
}
});
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: