安卓动画学习
2015-12-15 16:06
330 查看
Animation 补间动画
分两类,帧动画和补间动画
补间动画也叫做Tween动画,其动画方式分为4种:
淡入淡出(alpha)
平移(translate)
缩放(scale)
旋转(rotate)
01 alpha动画
public void doAlpha(View v){
Animation animation;
animation = new AlphaAnimationUtils.loadAnimation(this,R.anim.alpha);
(方法一:
alpha.xml:
<alpha
android:fromAlpha="0"
android:toAlpha="1"
android:duration ="5000"
xmlns:android = "http://schemas.android.com/apk/res/android">
)
//方法二:
animation = new AlphaAnimation(0f,1f);
animation.setDuration(5000);(设置时间,以毫秒为单位)
imageview.startAnimation(animation);
}
02 平移(translate)
<translate
android:duration="2000"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="100%"
android:toYDelta="100%"
android:fillAfter="true"(保持动画结束状态)
android:repeatCount="1"(重复的次数,不包括第一次)
android:repeaMode="reverse"(返回)
android:repeaMode="restart"(重新开始)
android:fillBefore
></translate>
public void doTranslate(View v){
Animation animation;
animation = new AlphaAnimationUtils.loadAnimation(this,R.anim.translate);
imageview.startAnimation(animation);
}
03 缩放(scale)
<scale
android:fromXScale="0"
android:fromYScale="0"
android:toScale="100%"
android:toScale="100%"
<--设置中心点位置-->
android:pivotX="0"
android:pivotY="0"
></scale>
public void doScale(View v){
Animation animation;
animation = new AlphaAnimationUtils.loadAnimation(this,R.anim.scale);
imageview.startAnimation(animation);
}
04 旋转(rotate)
<rotate
android:fromDegrees="0"
android:toDegrees="360"(可以设置旋转圈数)
android:duration="2000"
android:interpolator(用来设置加速方式)
android:repeatCount="2"(也可以设置旋转圈数)
android:pivotX="50%"
android:pivotY="50%"></rotate>
public void doScale(View v){
Animation animation;
animation = new AlphaAnimationUtils.loadAnimation(this,R.anim.rotate);
imageview.startAnimation(animation);
}
05 set动画集
<set
<alpha
android:duration="3000"
android:fromAlpha="0"
android:toAlpha="1"></alpha>
<scale
android:fromXScale="0"
android:fromYScale="0"
android:toXScale="100%"
android:toYScale="100%"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000">
</scale>
<rotate
android:duration="3000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset=""(设置开始时间,可以设置动画集相互播放的时间)
android:toDegrees="720"/>
</rotate>
></set>
public void AnimationSet(View v){
Animation animation;
animation = new AlphaAnimationUtils.loadAnimation(this,R.anim.set);
imageview.startAnimation(animation);
}
使用动画实现的图库:
主要代码:left_out_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="-100%"
android:toXDelta="0"
android:duration="1500"
/>
<alpha
android:fromAlpha="0.75"
android:toAlpha="1"
android:duration="1500"
/>
</set>
left_to_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="100%"
android:duration="1500"
/>
<alpha
android:fromAlpha="0.5"
android:toAlpha="1"
android:duration="1500"
/>
</set>
right_out_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="-100%"
android:duration="1500"
/>
<alpha
android:fromAlpha="0.5"
android:toAlpha="1"
android:duration="1500"
/>
</set>
right_to_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="100%"
android:duration="1500"
/>
<alpha
android:fromAlpha="0.5"
android:toAlpha="1"
android:duration="1500"
/>
</set>
imageswitcher.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.right_to_left));
imageswitcher.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.right_out_left));
分两类,帧动画和补间动画
补间动画也叫做Tween动画,其动画方式分为4种:
淡入淡出(alpha)
平移(translate)
缩放(scale)
旋转(rotate)
01 alpha动画
public void doAlpha(View v){
Animation animation;
animation = new AlphaAnimationUtils.loadAnimation(this,R.anim.alpha);
(方法一:
alpha.xml:
<alpha
android:fromAlpha="0"
android:toAlpha="1"
android:duration ="5000"
xmlns:android = "http://schemas.android.com/apk/res/android">
)
//方法二:
animation = new AlphaAnimation(0f,1f);
animation.setDuration(5000);(设置时间,以毫秒为单位)
imageview.startAnimation(animation);
}
02 平移(translate)
<translate
android:duration="2000"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="100%"
android:toYDelta="100%"
android:fillAfter="true"(保持动画结束状态)
android:repeatCount="1"(重复的次数,不包括第一次)
android:repeaMode="reverse"(返回)
android:repeaMode="restart"(重新开始)
android:fillBefore
></translate>
public void doTranslate(View v){
Animation animation;
animation = new AlphaAnimationUtils.loadAnimation(this,R.anim.translate);
imageview.startAnimation(animation);
}
03 缩放(scale)
<scale
android:fromXScale="0"
android:fromYScale="0"
android:toScale="100%"
android:toScale="100%"
<--设置中心点位置-->
android:pivotX="0"
android:pivotY="0"
></scale>
public void doScale(View v){
Animation animation;
animation = new AlphaAnimationUtils.loadAnimation(this,R.anim.scale);
imageview.startAnimation(animation);
}
04 旋转(rotate)
<rotate
android:fromDegrees="0"
android:toDegrees="360"(可以设置旋转圈数)
android:duration="2000"
android:interpolator(用来设置加速方式)
android:repeatCount="2"(也可以设置旋转圈数)
android:pivotX="50%"
android:pivotY="50%"></rotate>
public void doScale(View v){
Animation animation;
animation = new AlphaAnimationUtils.loadAnimation(this,R.anim.rotate);
imageview.startAnimation(animation);
}
05 set动画集
<set
<alpha
android:duration="3000"
android:fromAlpha="0"
android:toAlpha="1"></alpha>
<scale
android:fromXScale="0"
android:fromYScale="0"
android:toXScale="100%"
android:toYScale="100%"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000">
</scale>
<rotate
android:duration="3000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset=""(设置开始时间,可以设置动画集相互播放的时间)
android:toDegrees="720"/>
</rotate>
></set>
public void AnimationSet(View v){
Animation animation;
animation = new AlphaAnimationUtils.loadAnimation(this,R.anim.set);
imageview.startAnimation(animation);
}
使用动画实现的图库:
主要代码:left_out_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="-100%"
android:toXDelta="0"
android:duration="1500"
/>
<alpha
android:fromAlpha="0.75"
android:toAlpha="1"
android:duration="1500"
/>
</set>
left_to_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="100%"
android:duration="1500"
/>
<alpha
android:fromAlpha="0.5"
android:toAlpha="1"
android:duration="1500"
/>
</set>
right_out_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="-100%"
android:duration="1500"
/>
<alpha
android:fromAlpha="0.5"
android:toAlpha="1"
android:duration="1500"
/>
</set>
right_to_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="100%"
android:duration="1500"
/>
<alpha
android:fromAlpha="0.5"
android:toAlpha="1"
android:duration="1500"
/>
</set>
imageswitcher.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.right_to_left));
imageswitcher.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.right_out_left));
imageswitcher.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.left_to_right)); imageswitcher.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.left_out_right));
相关文章推荐
- 转:iOS界面-抽屉式交互
- ACE 编译
- 网站电脑访问没问题,手机访问跳到另一个网站(是个不良网站)
- centos6.6 安装 LXC
- [ 1002 ] 考试笔记 数据结构 简代码与小小说
- stdafx.h与Afx.h了解
- 修改光标
- Android Animations动画使用详解
- c++实现半同步半异步I/O的设计模式(half sync/half async)
- html自带的滚动标签
- jQuery Validate
- Windows下MySQL批量执行SQL脚本文件
- Hadoop2.x的 HA简介
- 关于myeclipse+maven(svn)的原本正确项目报红叉问题
- 使用代码给View添加约束
- java中的@retention and @interface
- 欢迎使用CSDN-markdown编辑器
- 通知中心
- 后缀数组模板
- inno setup检查是否已经安装