android动画(Animation)
2015-08-09 23:21
381 查看
AlphaAnimation 透明度
AlphaAnimationalphaAnimation = new AlphaAnimation(0, 1);
alphaAnimation.setDuration(1000);
alphaButton.startAnimation(alphaAnimation);
<?xml
version="1.0"encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0"
android:toAlpha="1"
android:duration="1000">
</alpha>
RotateAnimation 角度
//RotateAnimation rotateAnimation = new RotateAnimation(0, 360, 50,
// 50);//50,50是相对控件自身的XY偏移量
RotateAnimationrotateAnimation = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f,//
旋转点X坐标相对于自身比例一半的位置
Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(1000);
rotateButton.startAnimation(rotateAnimation);
// 调用Xml资源
rotateButton.startAnimation(AnimationUtils.loadAnimation(
MainActivity.this, R.anim.ro));
<?xml
version="1.0"encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:duration="1000"
android:pivotX="50%"
android:pivotY="50%">
</rotate>
ScaleAnimation 缩放
ScaleAnimationscaleAnimation = new ScaleAnimation(1, 1.5f, 1, 2,//x方向由1放大到1.5,y方向由1放大到2
Animation.RELATIVE_TO_SELF, 0.5f,//放大中心点X坐标在一半处
Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(1000);
scaleButton.startAnimation(scaleAnimation);
scaleButton.startAnimation(AnimationUtils.loadAnimation(
MainActivity.this, R.anim.sc));
<?xml
version="1.0"encoding="utf-8"?>
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%" xml文件中相对比例用百分比
android:pivotY="50%"
android:toXScale="1.5"
android:toYScale="2">
</scale>
TranslateAnimation 平移
TranslateAnimationtranslateAnimation = new TranslateAnimation(30,
200, 50, 100);//
移动x从30到200,
移动y方向从50到100,
都是相对像素
translateAnimation.setDuration(1000);
transButton.startAnimation(translateAnimation);
transButton.startAnimation(AnimationUtils.loadAnimation(
MainActivity.this, R.anim.tr));
<?xml
version="1.0"encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXDelta="30"
android:fromYDelta="50"
android:toXDelta="200"
android:toYDelta="100">
</translate>
多个Animation组合
AnimationSet animationSet=new AnimationSet(true);
animationSet.addAnimation(rotateAnimation);
rotateButton.startAnimation(animationSet);
动画监听
rotateAnimation.setAnimationListener(new AnimationListener() {
@Override
public
void onAnimationStart(Animation arg0) {
}
@Override
public
void onAnimationRepeat(Animation arg0) {
}
@Override
public
void onAnimationEnd(Animation arg0) {
}
});
AlphaAnimationalphaAnimation = new AlphaAnimation(0, 1);
alphaAnimation.setDuration(1000);
alphaButton.startAnimation(alphaAnimation);
<?xml
version="1.0"encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0"
android:toAlpha="1"
android:duration="1000">
</alpha>
RotateAnimation 角度
//RotateAnimation rotateAnimation = new RotateAnimation(0, 360, 50,
// 50);//50,50是相对控件自身的XY偏移量
RotateAnimationrotateAnimation = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f,//
旋转点X坐标相对于自身比例一半的位置
Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(1000);
rotateButton.startAnimation(rotateAnimation);
// 调用Xml资源
rotateButton.startAnimation(AnimationUtils.loadAnimation(
MainActivity.this, R.anim.ro));
<?xml
version="1.0"encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:duration="1000"
android:pivotX="50%"
android:pivotY="50%">
</rotate>
ScaleAnimation 缩放
ScaleAnimationscaleAnimation = new ScaleAnimation(1, 1.5f, 1, 2,//x方向由1放大到1.5,y方向由1放大到2
Animation.RELATIVE_TO_SELF, 0.5f,//放大中心点X坐标在一半处
Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(1000);
scaleButton.startAnimation(scaleAnimation);
scaleButton.startAnimation(AnimationUtils.loadAnimation(
MainActivity.this, R.anim.sc));
<?xml
version="1.0"encoding="utf-8"?>
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%" xml文件中相对比例用百分比
android:pivotY="50%"
android:toXScale="1.5"
android:toYScale="2">
</scale>
TranslateAnimation 平移
TranslateAnimationtranslateAnimation = new TranslateAnimation(30,
200, 50, 100);//
移动x从30到200,
移动y方向从50到100,
都是相对像素
translateAnimation.setDuration(1000);
transButton.startAnimation(translateAnimation);
transButton.startAnimation(AnimationUtils.loadAnimation(
MainActivity.this, R.anim.tr));
<?xml
version="1.0"encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXDelta="30"
android:fromYDelta="50"
android:toXDelta="200"
android:toYDelta="100">
</translate>
多个Animation组合
AnimationSet animationSet=new AnimationSet(true);
animationSet.addAnimation(rotateAnimation);
rotateButton.startAnimation(animationSet);
动画监听
rotateAnimation.setAnimationListener(new AnimationListener() {
@Override
public
void onAnimationStart(Animation arg0) {
}
@Override
public
void onAnimationRepeat(Animation arg0) {
}
@Override
public
void onAnimationEnd(Animation arg0) {
}
});
相关文章推荐
- mac android studio NDK 安装使用(不用翻墙)
- Android进阶之采用TabHost和RadioButton实现底部页面导航
- android笔记--Intent和IntentFilter详解
- Android中的Handler机制
- 如何通过Android Studio 或者ADT 使用VS的安卓模拟器
- android引导页的实现
- Android FlowLayout
- android学习笔记(7)AbsoluteLayout+FrameLayout+RelativeLayout+TableLayout四大布局方式
- android ftp多线程多任务下载时的listview滑动列表错乱解决方法
- Android小记:ViewStub的使用
- android.content.res.Resources$NotFoundException: String resource ID #0x0
- Android开发环境的配置(Ubuntu 14.04 64位)
- Android View滚动、拉伸到顶/底部弹性回弹复位
- Android中的cookie管理简介
- android 进程/线程管理(四)续----消息机制的思考(自定义消息机制)
- android中可以使用bitmap的平铺,镜像平铺等减小图片带来的apk过大的问题
- Android-PullToRefresh下拉刷新,上拉加载
- android view(二)
- Android仿360手机卫士波浪球进度的实现
- Android基础之Activity的生命周期