Android开发教程Tween动画实现代码
2014-03-05 09:29
465 查看
Android开发教程之Tween动画的实现。
首先它属于系统提供的绘制动画的方法。Tween动画主要的功能是在绘制动画前设置动画绘制的轨迹,包括时间,位置 ,等等。但是Tween动画的缺点是它只能设置起始点与结束点的两帧,中间过程全部由系统帮我们完成。所以在帧数比较多的游戏开发中是不太会用到它的。
Tween一共提供了4中动画的效果
Scale:缩放动画
Rotate:旋转动画
Translate:移动动画
Alpha::透明渐变动画
Tween与Frame动画类似都需要在res\anim路径下创建动画的 布局文件
1.Scale缩放动画
标签为缩放节点
android:fromXscale="1.0" 表示开始时X轴缩放比例为 1.0 (原图大小 * 1.0 为原图大小)
android:toXscale="0.0"表示结束时X轴缩放比例为0.0(原图大小 *0.0 为缩小到看不见)
android:fromYscale="1.0" 表示开始时Y轴缩放比例为 1.0 (原图大小 * 1.0 为原图大小)
android:toYscale="0.0"表示结束时Y轴缩放比例为0.0(原图大小 *0.0 为缩小的看不到了)
android:pivotX="50%" X轴缩放的位置为中心点
android:pivotY="50%" Y轴缩放的位置为中心点
android:duration="2000" 动画播放时间 这里是2000毫秒也就是2秒
这个动画布局设置动画从大到小进行缩小。
android:fromXScale="1.0"
android:toXScale="0.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000">
复制代码
代码如下
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.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class ScaleActivity extends Activity {
/**缩小动画按钮**/
Button mButton0 = null;
/**放大动画按钮**/
Button mButton1 = null;
/**显示动画的ImageView**/
ImageView mImageView = null;
/**缩小动画**/
Animation mLitteAnimation = null;
/**放大动画**/
Animation mBigAnimation = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scale);
/**拿到ImageView对象**/
mImageView = (ImageView)findViewById(R.id.imageView);
/**加载缩小与放大动画**/
mLitteAnimation = AnimationUtils.loadAnimation(this, R.anim.scalelitte);
mBigAnimation = AnimationUtils.loadAnimation(this, R.anim.scalebig);
mButton0 = (Button)findViewById(R.id.button0);
mButton0.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
/**播放缩小动画**/
mImageView.startAnimation(mLitteAnimation);
}
});
mButton1 = (Button)findViewById(R.id.button1);
mButton1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
/**播放放大动画**/
mImageView.startAnimation(mBigAnimation);
}
});
}
}
首先它属于系统提供的绘制动画的方法。Tween动画主要的功能是在绘制动画前设置动画绘制的轨迹,包括时间,位置 ,等等。但是Tween动画的缺点是它只能设置起始点与结束点的两帧,中间过程全部由系统帮我们完成。所以在帧数比较多的游戏开发中是不太会用到它的。
Tween一共提供了4中动画的效果
Scale:缩放动画
Rotate:旋转动画
Translate:移动动画
Alpha::透明渐变动画
Tween与Frame动画类似都需要在res\anim路径下创建动画的 布局文件
1.Scale缩放动画
标签为缩放节点
android:fromXscale="1.0" 表示开始时X轴缩放比例为 1.0 (原图大小 * 1.0 为原图大小)
android:toXscale="0.0"表示结束时X轴缩放比例为0.0(原图大小 *0.0 为缩小到看不见)
android:fromYscale="1.0" 表示开始时Y轴缩放比例为 1.0 (原图大小 * 1.0 为原图大小)
android:toYscale="0.0"表示结束时Y轴缩放比例为0.0(原图大小 *0.0 为缩小的看不到了)
android:pivotX="50%" X轴缩放的位置为中心点
android:pivotY="50%" Y轴缩放的位置为中心点
android:duration="2000" 动画播放时间 这里是2000毫秒也就是2秒
这个动画布局设置动画从大到小进行缩小。
android:fromXScale="1.0"
android:toXScale="0.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000">
复制代码
代码如下
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.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class ScaleActivity extends Activity {
/**缩小动画按钮**/
Button mButton0 = null;
/**放大动画按钮**/
Button mButton1 = null;
/**显示动画的ImageView**/
ImageView mImageView = null;
/**缩小动画**/
Animation mLitteAnimation = null;
/**放大动画**/
Animation mBigAnimation = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scale);
/**拿到ImageView对象**/
mImageView = (ImageView)findViewById(R.id.imageView);
/**加载缩小与放大动画**/
mLitteAnimation = AnimationUtils.loadAnimation(this, R.anim.scalelitte);
mBigAnimation = AnimationUtils.loadAnimation(this, R.anim.scalebig);
mButton0 = (Button)findViewById(R.id.button0);
mButton0.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
/**播放缩小动画**/
mImageView.startAnimation(mLitteAnimation);
}
});
mButton1 = (Button)findViewById(R.id.button1);
mButton1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
/**播放放大动画**/
mImageView.startAnimation(mBigAnimation);
}
});
}
}
相关文章推荐
- Android开发之Tween(补间动画)完全解析(下)——代码实现
- Android开发(26)--补间动画(Tween)的实现
- Android游戏开发学习笔记(一):tweened animation自定义动画的实现
- Android开发之Tween(补间动画)完全解析(上)——xml文件配置的实现
- android开发游记:通过xml配置快速实现点击热点效果和渐变动画(不用java代码)
- Android动画Animation之Tween用代码实现动画
- Android游戏开发之Tween动画的实现(三十二)
- Android动画Animation之Tween用代码实现动画效果
- 【Android动画】之Tween动画 (渐变、缩放、位移、旋转)代码中的实现
- Android游戏开发之Tween动画的实现
- Android游戏开发之Tween动画的实现(三十二)
- Android开发教程:文字翻转动画的实现
- android游戏开发框架libgdx的使用(二十三)—使用Universal Tween Engine实现动画效果
- android基础笔记——补间动画(Tween)代码实现
- 【Android 基础】Animation 动画介绍和实现【帧动画和Tween动画【在代码和xml中实现】】
- Android开发(26)--补间动画(Tween)的实现
- Android开发(26)--补间动画(Tween)的实现
- Android开发之Tween动画实现方法
- 每日一学(九)Android动画---Tween动画的代码实现
- Android研究之游戏开发帧动画实现