package com.yangguangfu.cn;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
public class ScaleAnimationDemoActivity extends Activity implements
OnClickListener {
private ImageView top_left;
private ImageView top_right;
private ImageView bottom_left;
private ImageView bottom_right;
private ImageView center;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) { // 要使用findViewById,
super.onCreate(savedInstanceState); // 做为使用者介面
setContentView(R.layout.second);
// 取得UI 介面中的View 物件
// 取得View 物件后,再透过转换成实际的物件
top_left = (ImageView) findViewById(R.id.top_left);
top_right = (ImageView) findViewById(R.id.top_right);
bottom_left = (ImageView) findViewById(R.id.bottom_left);
bottom_right = (ImageView) findViewById(R.id.bottom_right);
center = (ImageView) findViewById(R.id.center);
top_left.setOnClickListener(this);
top_right.setOnClickListener(this);
bottom_left.setOnClickListener(this);
bottom_right.setOnClickListener(this);
center.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.top_left:
topLeftScaleAnimation(v);
break;
case R.id.top_right:
topRightScaleAnimation(v);
break;
case R.id.bottom_left:
bottomLiftScaleAnimation(v);
break;
case R.id.bottom_right:
bottomRightScaleAnimation(v);
break;
case R.id.center:
centerScaleAnimation(v);
break;
}
}
private Animation topLeftanimation;
private boolean istopLeft = false;
private void topLeftScaleAnimation(final View v) {
if (!istopLeft) {
topLeftanimation = new ScaleAnimation(1.0f, 4.0f, 1.0f, 4.0f,
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f);
istopLeft = true;
} else {
topLeftanimation = new ScaleAnimation(4.0f, 1.0f, 4.0f, 1.0f,
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f);
istopLeft = false;
}
// 动画开始到结束的执行时间(1000 = 1 秒)
topLeftanimation.setDuration(2000);
// 动画重复次数(-1 表示一直重复)
// am.setRepeatCount(1);
topLeftanimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
top_left.setEnabled(true);
}
});
topLeftanimation.setFillAfter(true);
// 图片配置动画
top_left.setAnimation(topLeftanimation);
// Help();
// handler.sendEmptyMessageDelayed(topHand, 2000);
// top_left.setLayoutParams(lp);
// 动画开始
topLeftanimation.startNow();
top_left.setEnabled(false);
}
private static final int topHand = 6;
private boolean isBottomLift = false;
Animation bottomLiftScaleAnimation = null;
private void bottomLiftScaleAnimation(View v) {
if (!isBottomLift) {
bottomLiftScaleAnimation = new ScaleAnimation(1.0f, 4.0f, 1.0f,
4.0f, Animation.RELATIVE_TO_SELF, 0f,
Animation.RELATIVE_TO_SELF, 1.0f);
isBottomLift = true;
} else {
bottomLiftScaleAnimation = new ScaleAnimation(4.0f, 1.0f, 4.0f,
1.0f, Animation.RELATIVE_TO_SELF, 0f,
Animation.RELATIVE_TO_SELF, 1.0f);
isBottomLift = false;
}
// 动画开始到结束的执行时间(1000 = 1 秒)
bottomLiftScaleAnimation.setDuration(2000);
// 动画重复次数(-1 表示一直重复)
// bottomLiftScaleAnimation.setRepeatCount(-1);
bottomLiftScaleAnimation.setFillAfter(true);
// 图片配置动画
bottom_left.setAnimation(bottomLiftScaleAnimation);
bottomLiftScaleAnimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
bottom_left.setEnabled(true);
}
});
// 动画开始
bottomLiftScaleAnimation.startNow();
bottom_left.setEnabled(false);
}
private boolean isBottomRigth = false;
Animation bottomRightScaleAnimation;
private void bottomRightScaleAnimation(View v) {
if (!isBottomRigth) {
bottomRightScaleAnimation = new ScaleAnimation(1.0f, 4.0f, 1.0f,
4.0f, Animation.RELATIVE_TO_SELF, 1.0f,
Animation.RELATIVE_TO_SELF, 1.0f);
isBottomRigth = true;
} else {
bottomRightScaleAnimation = new ScaleAnimation(4.0f, 1.0f, 4.0f,
1.0f, Animation.RELATIVE_TO_SELF, 1.0f,
Animation.RELATIVE_TO_SELF, 1.0f);
isBottomRigth = false;
}
// 动画开始到结束的执行时间(1000 = 1 秒)
bottomRightScaleAnimation.setDuration(2000);
bottomRightScaleAnimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
bottom_right.setEnabled(true);
}
});
// 动画重复次数(-1 表示一直重复)
// bottomRightScaleAnimation.setRepeatCount(-1);
bottomRightScaleAnimation.setFillAfter(true);
// 图片配置动画
bottom_right.setAnimation(bottomRightScaleAnimation);
// 动画开始
bottomRightScaleAnimation.startNow();
bottom_right.setEnabled(false);
}
private Animation topRightScaleAnimation;
private boolean isTopRight = false;
private void topRightScaleAnimation(View v) {
if (!isTopRight) {
topRightScaleAnimation = new ScaleAnimation(1.0f, 4.0f, 1.0f, 4.0f,
Animation.RELATIVE_TO_SELF, 1.0f,
Animation.RELATIVE_TO_SELF, 0.0f);
isTopRight = true;
} else {
topRightScaleAnimation = new ScaleAnimation(4.0f, 1.0f, 4.0f, 1.0f,
Animation.RELATIVE_TO_SELF, 1.0f,
Animation.RELATIVE_TO_SELF, 0.0f);
isTopRight = false;
}
topRightScaleAnimation.setDuration(2000);
// 动画重复次数(-1 表示一直重复)
// topRightScaleAnimation.setRepeatCount(-1);
// 图片配置动画
top_right.setAnimation(topRightScaleAnimation);
topRightScaleAnimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
top_right.setEnabled(true);
}
});
// 动画开始
topRightScaleAnimation.startNow();
topRightScaleAnimation.setFillAfter(true);
top_right.setEnabled(false);
}
private boolean isCenter = false;
Animation centerScaleAnimation;
private void centerScaleAnimation(View v) {
if (!isCenter) {
centerScaleAnimation = new ScaleAnimation(1.0f, 4.0f, 1.0f, 4.0f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
isCenter = true;
} else {
centerScaleAnimation = new ScaleAnimation(4.0f, 1.0f, 4.0f, 1.0f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
isCenter = false;
}
centerScaleAnimation.setDuration(2000);
centerScaleAnimation.setFillAfter(true);
// 动画重复次数(-1 表示一直重复)
// centerScaleAnimation.setRepeatCount(-1);
centerScaleAnimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
center.setEnabled(true);
// TODO Auto-generated method stub
}
});
// 图片配置动画
center.setAnimation(centerScaleAnimation);
// 动画开始
centerScaleAnimation.startNow();
center.setEnabled(false);
}
}
1,动画执行之前
2,动画执行之后
- 大小: 12.3 KB
- 大小: 87.7 KB
分享到:
相关推荐
本节讲解ScaleAnimation 动画在应用中的实现,有需要的朋友可以参考下
android scaleanimation 代码~~~~~~~~~~~~~~~~~~~~~~
android Tween ScaleAnimation TranlateAnimation
缩放Scale动画(ScaleAnimation),支持多值,,支持设置轴点 4.全屏滑动Slide动画(SlideAnimation),支持上下左右四个方向移入与移出 5.自身控件范围内滑动动画(SlideUnderneathAnimation),支持上下左右四个...
android动画 AlphaAnimation(透明度动画效果 );RotateAnimation(旋转动画效果);ScaleAnimation(缩放动画效果 ); TranslateAnimation(位移动画效果 )
缩放动画标签,使用的子类名称为ScaleAnimation,实现的效果是整个View的放大或者缩小。 旋转动画标签使用的子类名称是RotateAnimation,实现的效果是将整个View进行旋转。 透明度动画标签使用的子类名称是...
Android各种动画效果ScaleAnimation,AlphaAnimation,TranslateAnimation,RotateAnimation(文章结尾有代码)
Android Java动画使用Java的Android动画规模建设者ScaleAnimation(Context context,AttributeSet attrs)从资源加载ScaleAnimation时使用的构造方法。 ScaleAnimation(float fromX,float toX,float fromY,...
包含AlphaAnimation渐变效果 TranslateAnimation:位移渐变 ScaleAnimation:缩放渐变 RotateAnimation:旋转渐变 AnimationSet:组合渐变... frameAnimation:帧动画的xml和代码实现方式,非常适合新手朋友参考。
本文实例讲述了Android编程实现仿心跳动画效果的方法。分享给大家供大家参考,具体如下: // 按钮模拟心脏跳动 private void playHeartbeatAnimation() { AnimationSet animationSet = new AnimationSet(true); ...
在Andriod开发中,Animation是用来给控件... 根据我们需要的动态效果创建一个Animation类,主要有4个这样的类,分别为AlphaAnimation,ScaleAnimation,RotateAnimation,TranslateAnimation,分别对应着一种动画效果。
AlphaAnimation缩放动画-ScaleAnimation位移动画-TranslateAnimation旋转动画-RotateAnimation动画组合-AnimationSet代码实现补间动画透明度动画(AlphaAnimation)缩放动画(ScaleAnimation)位移动画...
之前说过了在Android中,动画Animation的实现有两种方式:Tween Animation(渐变动画)和Frame Animation(帧动画)。渐变动画是通过对场景里的对象不断做图像变换(平移、缩放、旋转等)产生动画效果。帧动画则是...
对当前的ImageView创建了一个ScaleAnimation动画,演示ScaleAnimation动画的使用。
android动画基础 XML中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 translate 画面转换位置移动动画效果 rotate 画面转移旋转动画效果 JavaCode中 AlphaAnimation 渐变透明度动画效果 ScaleAnimation ...
android 下拉,淡入淡出特效源码 依赖support v7 // /** * PopupWindow上菜单进入动画 */ public static Animation createPopupAnimIn(Context context, int fromYDelta) { AnimationSet animationSet = new ...
AlphaAnimation 渐变透明度动画效果 ScaleAnimation 渐变尺寸伸缩动画效果 TranslateAnimation 画面转换位置移动动画效果 RotateAnimation 画面转移旋转动画效果
补间动画 AlphaAnimation TranslateAnimation ScaleAnimation RotateAnimation
1.2.android实现动画方式: 编码方式 xml方式 1.3. 动画Api : scaleAnimation1.setStartOffset(1000); // 动画延迟时间 scaleAnimation1.setDuration(10000); // 持续时间 scaleAnimation