Android样式的开发:View Animation篇
来源:互联网 发布:ubuntu 启动过程 编辑:程序博客网 时间:2024/04/19 11:32
转载自Keegan小钢
原文链接:http://keeganlee.me/post/android/20151003
<alpha>
- android:duration 动画从开始到结束持续的时长,单位为毫秒
- android:fromAlpha 动画开始时的透明度,0.0为全透明,1.0为不透明,默认为1.0
- android:toAlpha 动画结束时的透明度,0.0为全透明,1.0为不透明,默认为1.0
<!-- res/anim/fade_in.xml --><?xml version="1.0" encoding="utf-8"?><alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromAlpha="0.0" android:toAlpha="1.0" />
view.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in));
AlphaAnimation fadeInAnimation = (AlphaAnimation) AnimationUtils.loadAnimation(this, R.anim.fade_in);view.startAnimation(fadeInAnimation);
<scale>
- android:duration 动画从开始到结束持续的时长,单位为毫秒
- android:fromXScale 动画开始时X坐标上的缩放尺寸
- android:toXScale 动画结束时X坐标上的缩放尺寸
- android:fromYScale 动画开始时Y坐标上的缩放尺寸
android:toYScale 动画结束时Y坐标上的缩放尺寸
PS:以上四个属性,0.0表示缩放到没有,1.0表示正常无缩放,小于1.0表示收缩,大于1.0表示放大android:pivotX 缩放时的固定不变的X坐标,一般用百分比表示,0%表示左边缘,100%表示右边缘
android:pivotY 缩放时的固定不变的Y坐标,一般用百分比表示,0%表示顶部边缘,100%表示底部边缘
<!-- res/anim/zoom_out.xml --><?xml version="1.0" encoding="utf-8"?><scale xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromXScale="1.0" android:fromYScale="1.0" android:pivotX="0%" android:pivotY="100%" android:toXScale="1.5" android:toYScale="1.5" />
ScaleAnimation zoomOutAnimation = (ScaleAnimation) AnimationUtils.loadAnimation(this, R.anim.zoom_out);view.startAnimation(zoomOutAnimation);
<translate>
- android:duration 动画从开始到结束持续的时长,单位为毫秒
- android:fromXDelta 起始位置的X坐标的偏移量
- android:toXDelta 结束位置的X坐标的偏移量
- android:fromYDelta 起始位置的Y坐标的偏移量
- android:toYDelta 结束位置的Y坐标的偏移量
<!-- res/anim/move_left_to_right.xml --><?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="2000" android:fromXDelta="-100%" android:fromYDelta="0" android:toXDelta="100%p" android:toYDelta="0" />
TranslateAnimation moveAnimation = (TranslateAnimation) AnimationUtils.loadAnimation(this, R.anim.move_left_to_right);view.startAnimation(moveAnimation);
<rotate>
- android:duration 动画从开始到结束持续的时长,单位为毫秒
- android:fromDegrees 旋转开始的角度
- android:toDegrees 旋转结束的角度
- android:pivotX 旋转中心点的X坐标,纯数字表示相对于View本身左边缘的像素偏移量;带"%"后缀时表示相对于View本身左边缘的百分比偏移量;带"%p"后缀时表示相对于父View左边缘的百分比偏移量
- android:pivotY 旋转中心点的Y坐标,纯数字表示相对于View本身顶部边缘的像素偏移量;带"%"后缀时表示相对于View本身顶部边缘的百分比偏移量;带"%p"后缀时表示相对于父View顶部边缘的百分比偏移量
<!-- res/anim/rotate_one.xml --><?xml version="1.0" encoding="utf-8"?><rotate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="2000" android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%" />
RotateAnimation rotateAnimation = (RotateAnimation) AnimationUtils.loadAnimation(this, R.anim.rotate_one);view.startAnimation(rotateAnimation);
<set>
<!-- res/anim/move_and_scale.xml --><?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="2000"> <translate android:fromXDelta="0" android:fromYDelta="0" android:toXDelta="200%" android:toYDelta="0" /> <scale android:fromXScale="1.0" android:fromYScale="1.0" android:pivotX="0%" android:pivotY="100%" android:toXScale="1.5" android:toYScale="1.5" /></set>
通用属性
- android:duration 动画从开始到结束持续的时长,单位为毫秒
- android:detachWallpaper 设置是否在壁纸上运行,只对设置了壁纸背景的窗口动画(window animation)有效。设为true,则动画只在窗口运行,壁纸背景保持不变
- android:fillAfter 设置为true时,动画执行完后,View会停留在动画的最后一帧;默认为false;如果是动画集,需在<set>标签中设置该属性才有效
- android:fillBefore 设置为true时,动画执行完后,View回到动画执行前的状态,默认即为true
- android:fillEnabled 设置为true时,android:fillBefore的值才有效,否则android:fillBefore会被忽略
- android:repeatCount 设置动画重复执行的次数,默认为0,即不重复;可设为-1或infinite,表示无限重复
android:repeatMode 设置动画重复执行的模式,可设为以下两个值其中之一:
- restart 动画重复执行时从起点开始,默认为该值
- reverse 动画会反方向执行
android:startOffset 设置动画执行之前的等待时长,毫秒为单位;重复执行时,每次执行前同样也会等待一段时间
android:zAdjustment 表示被设置动画的内容在动画运行时在Z轴上的位置,取值为以下三个值之一:
- normal 默认值,保持内容在Z轴上的位置不变
- top 保持在Z周最上层
- bottom 保持在Z轴最下层
android:interpolator 设置动画速率的变化,比如加速、减速、匀速等,需要指定Interpolator资源,后面再详细讲解
PS:<set>标签还有个android:shareInterpolator属性,设置为true时则可将interpolator应用到所有子元素中
Interpolator
- <accelerateDecelerateInterpolator> 在动画开始与结束时速率改变比较慢,在中间的时候加速。没有可更改设置的属性,所以设置的效果和系统提供的一样
<accelerateInterpolator> 在动画开始时速率改变比较慢,然后开始加速。有一个属性可以设置加速的速率
- android:factor 浮点值,加速的速率,默认为1
<anticipateInterpolator> 动画开始的时候向后然后往前抛。有一个属性设置向后拉的值
- android:tension 浮点值,向后的拉力,默认为2,当设为0时,则不会有向后的动画了
<anticipateOvershootInterpolator> 动画开始的时候向后然后向前抛,会抛超过目标值后再返回到最后的值。可设置两个属性
- android:tension 浮点值,向后的拉力,默认为2,当设为0时,则不会有向后的动画了
- android:extraTension 浮点值,拉力的倍数,默认为1.5(2*1.5),当设为0时,则不会有拉力了
<bounceInterpolator> 动画结束的时候会弹跳。没有可更改设置的属性
<cycleInterpolator> 动画循环做周期运动,速率改变沿着正弦曲线。有一个属性设置循环次数
- android:cycles 整数值,循环的次数,默认为1
<decelerateInterpolator> 在动画开始时速率改变比较快,然后开始减速。有一个属性设置减速的速率
- android:factor 浮点值,减速的速率,默认为1
<linearInterpolator> 动画匀速播放。没有可更改设置的属性
<overshootInterpolator> 动画向前抛,会抛超过最后值,然后再返回。有一个属性
- android:tension 浮点值,超出终点后的拉力,默认为2
<!-- res/anim/my_interpolator.xml --><?xml version="1.0" encoding="utf-8"?><anticipateOvershootInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:tension="3" android:extraTension="2" />
<!-- res/anim/rotate_one.xml --><?xml version="1.0" encoding="utf-8"?><rotate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="2000" android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%" android:interpolator="@anim/my_interpolator" />
写在最后
- Android样式的开发:View Animation篇
- Android样式的开发:View Animation篇
- Android样式的开发:View Animation篇
- Android样式的开发:View Animation篇
- Android样式的开发:View Animation篇
- Android样式的开发:View Animation篇
- Android样式的开发:View Animation篇
- Android样式的开发:View Animation篇
- Android样式的开发:View Animation篇
- Android样式的开发:View Animation篇
- Android样式的开发:View Animation篇
- Android样式的开发:View Animation篇
- ANDROID样式的开发:VIEW ANIMATION篇
- 【转载】Android样式的开发:View Animation篇
- Android样式的开发(五):View Animation篇
- (五)Android 样式的开发:View Animation 篇
- Android样式的开发:Property Animation篇
- Android样式的开发:Property Animation篇
- Redhat Linux安装Tomcat
- Linux Debian下安装tomcat7
- iOS 异步加载刷新
- c++前向声明
- 序列化和反序列化
- Android样式的开发:View Animation篇
- 二,使用框架完成http_python服务器
- Android样式的开发:Property Animation篇
- 定位坐标偏差
- C++堆和栈简析
- Mysql Innodb的事务和锁
- Java中系统属性Properties介绍 System.getProperty()参数大全-tomcat设置参数,java获取
- Material Design之RecyclerView
- IOCP例子一