Android 动画
来源:互联网 发布:软件正版化实施方案 编辑:程序博客网 时间:2024/06/06 03:51
下面是Android中的一些animation效果,记录之。
下面的动画都是基于ImageView来做的。
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" android:id="@+id/imageView" />
透明度渐变
透过透明度渐变,我们可以实现一些淡入淡出功效。要实现该动画效果,我们可以遵循以下步骤
1. 在res目录下新建文件夹anim存放关于动画的xml文件
2. 定义动画文件: alpha.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator" android:shareInterpolator="false" > <!-- @android:anim/linear_interpolator: 以常量速率改变 --> <!-- 淡出: 1.5s --> <alpha android:fromAlpha="1" android:toAlpha="0" android:duration="1500" /></set>
3. 在Activity中设置动画
//透明度动画 Animation alphaAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.alpha); alphaAnimation.setFillAfter(true); //停止后停留在最后状态 imageView.startAnimation(alphaAnimation);
/** * fillBefore是指动画结束时画面停留在此动画的第一帧 * fillAfter是指动画结束是画面停留在此动画的最后一帧 */
放大缩小
过程和上面类似,下面是xml文件: scale.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator" android:shareInterpolator="false" > <!-- @android:anim/linear_interpolator: 以常量速率改变 --> <!-- 以图片中心为轴3s内放大1.5倍 --> <scale android:fromXScale="1" android:toXScale="1.5" android:fromYScale="1" android:toYScale="1.5" android:pivotX="50%" android:pivotY="50%" android:duration="3000" /></set>
平移
平移的xml: translate.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator" android:shareInterpolator="false" > <!-- @android:anim/linear_interpolator: 以常量速率改变 --> <!-- 在1.5s内从原来位置平移到父元素(50%, 50%)位置 --> <translate android:fromXDelta="0" android:toXDelta="50%p" android:fromYDelta="0" android:toYDelta="50%p" android:duration="1500" /></set>
旋转
旋转的xml: rotate.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator" android:shareInterpolator="false" > <!-- @android:anim/linear_interpolator: 以常量速率改变 --> <!-- 1.5s内中心旋转180度 --> <rotate android:fromDegrees="0" android:toDegrees="180" android:pivotX="50%" android:pivotY="50%" android:duration="1500" /></set>
另外,在一个动画中,可以同时存在几种不同类型的动画。
0 0
- Android动画--视图动画
- Android动画--属性动画
- android动画 -- 属性动画
- Android:动画:tween动画
- Android:动画:Frame动画
- Android动画动画二
- Android动画-属性动画
- Android动画【属性动画】
- Android动画-帧动画
- Android动画--帧动画
- Android动画--属性动画
- Android动画-View动画
- android 动画 -- tween动画
- android 动画
- android动画
- android动画
- android动画
- Android动画
- shell中各括号
- Scala println Array
- HDU-2955 Robberies 01背包 + 概率
- android:ClassNotFoundException for Activity class的解决方法
- Android知识杂记
- Android 动画
- asp.net_Excel数据导入数据库
- [算法系列之二]二叉树各种遍历
- Windows学习心得【对话框2】
- 怎样编译 fmb & pld 文件
- DIV设置位置居中
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- Android SQLite性能分析
- C# 发送邮件类及示例 (不知是修改了哪位博主的了)