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
分享到:
相关推荐
在Android开发中,ScaleAnimation是动画库中的一个关键部分,用于实现对象的缩放效果。它允许我们在指定的坐标轴上放大或缩小视图,从而为用户界面增添动态感和交互性。本篇文章将深入探讨如何使用代码创建并应用...
Android提供了多种动画类型,其中包括AlphaAnimation、ScaleAnimation、TranslateAnimation和RotateAnimation。本节我们将深入探讨ScaleAnimation,它主要用于对象的缩放效果。 ScaleAnimation允许你在X轴和Y轴上对...
本文将深入探讨四种主要的渐变动画:Alpha(透明度)、Scale(缩放)、Translate(平移)和Rotate(旋转),以及如何通过Java代码和XML两种方式来实现这些动画。 1. **Alpha渐变动画**: Alpha动画主要用于改变...
Tween动画和ScaleAnimation是Android视图动画系统中的两个重要概念,它们帮助开发者实现丰富的视觉效果。在这个名为"Tween_android.rar_ScaleAnimation_android"的压缩包中,可能包含了一个示例项目,用于演示如何在...
"Android代码-动画顺序播放源码.zip"这个资源包提供了一个实现动画顺序播放的示例代码,这对于开发者来说是极有价值的。在Android平台上,我们可以使用多种方式来创建动画,包括属性动画(Property Animation)、...
"BaseAnimation数百种动画效果源码"这个资源包含了大量用于Android应用的动画效果实现,这对于开发者来说是一份宝贵的参考资料。下面我们将深入探讨Android动画体系以及这些源码可能涵盖的知识点。 1. **属性动画...
在Android中,补间动画主要通过`Animation`类和其子类来实现,如`AlphaAnimation`(透明度变化)、`ScaleAnimation`(缩放)、`TranslateAnimation`(移动)和`RotateAnimation`(旋转)。开发者可以通过调整这些...
本资料“安卓搜索相关相关-如何用Android实现搜索输入框的动画效果.rar”提供了一些关于如何在Android平台上创建这种效果的代码示例和教程。 首先,我们要理解Android中的搜索输入框通常是通过`EditText`组件来实现...
在Android平台上,实现广告播放通常涉及到一系列的动画效果,这些效果可以使用户界面更加生动和吸引人。本节我们将深入探讨如何使用Android动画机制来创建图片的平移和缩放效果,以及如何扩展这一机制来实现更多...
本文将深入探讨在Android中实现的各种动画效果,包括旋转动画、折叠翻转、点赞动画、折叠书架、按钮切换动画以及模糊动画等。 1. **旋转动画**: 旋转动画在Android中可以通过` RotateAnimation `类来实现。开发者...
这个名为“Android应用源码安卓动画合集大全加站长代码库.zip”的压缩包文件显然包含了大量的Android应用源码,特别是专注于动画实现的示例。这些源码可以帮助开发者深入理解Android动画系统,提升自己的编程技能。 ...
本文将详细解析"Android界面切换动画效果源代码"的相关知识点,包括如何实现、调整以及优化动画效果。 1. **Android 动画系统**: Android 提供了两种主要的动画机制:属性动画(Property Animation)和视图动画...
这个"Android代码(动画).zip"文件很可能包含了一些示例代码,用于展示如何在Android应用中实现各种类型的动画。让我们深入探讨一下Android动画相关的知识点。 1. **帧动画**:帧动画是通过连续播放一系列图片来...
"Android的秋千摇摆动画代码例子"是一个示例项目,展示了如何实现类似钟摆或秋千的左右摇摆动画效果。这种动画常见于游戏、模拟器或者任何需要物体动态摆动的情境中。接下来,我们将深入探讨如何在Android中创建此类...
在Android开发中,属性动画(Property Animation)是一个强大的工具,它可以为用户界面带来生动和吸引人的动态效果。本文将深入探讨如何使用属性动画实现一个酷炫的登录界面,以响应群友分享的登录原型图。 首先,...
补间动画通常通过`Animation`类及其子类如`AlphaAnimation`、`RotateAnimation`、`ScaleAnimation`等来实现。例如,一个简单的圆形Loading动画可以通过连续旋转来创建: ```java RotateAnimation rotateAnim = new...
Android提供了一系列的动画类,如TranslateAnimation(平移动画)、ScaleAnimation(缩放动画)和AlphaAnimation(透明度动画)。我们可以根据需求组合这些动画,创建出弹出和收回的效果。 例如,为按钮菜单创建一...
我们将深入探讨Android动画机制以及如何通过代码实现这些效果。 在Android中,动画主要分为两种类型:Property Animation(属性动画)和View Animation(视图动画)。视图动画系统主要存在于API 1.0到3.0之间,而...
除了代码实现,Android还支持在XML中定义动画。这使得在布局文件中声明和管理动画变得更加方便。`animator`和`animation`标签分别用于定义属性动画和视图动画。 五、使用源码学习 在"简单2D动画源码"中,你可以找到...