Android动画
2015-07-14 14:59
441 查看
一 旋转动画
1、定义一个ImageView
定义一个ImageView是为了装载图片,其中的图片将被rotate用来进行旋转,其他View亦可。
资源文件为
2、定义rotate旋转效果
在res/anim文件夹下新建tip.xml文件,内容如下
含义表示从0到359度开始循环旋转,0-359(若设置成360在停止时会出现停顿现象)度旋转所用时间为500ms,旋转中心距离view的左顶点为50%距离,距离view的上边缘为50%距离,即正中心,具体每个含义见下面的具体属性介绍。
初始化 :
开始旋转 :
停止旋转 :
二 , 渐变动画
首先是AlphaAnimation。alpha_anim.xml:
二 ,缩放动画 ScaleAnimation
scale_anim.xml
三,旋转动画 rotate_anim.xml:
四 ,平移动画
1、定义一个ImageView
定义一个ImageView是为了装载图片,其中的图片将被rotate用来进行旋转,其他View亦可。
资源文件为
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/infoOperating" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/operating" android:scaleType="center"> </ImageView> </LinearLayout>
ImageView infoOperatingIV = (ImageView)findViewById(R.id.infoOperating);
2、定义rotate旋转效果
在res/anim文件夹下新建tip.xml文件,内容如下
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:fromDegrees="0" android:toDegrees="359" android:duration="500" android:repeatCount="-1" android:pivotX="50%" android:pivotY="50%" /> </set>
含义表示从0到359度开始循环旋转,0-359(若设置成360在停止时会出现停顿现象)度旋转所用时间为500ms,旋转中心距离view的左顶点为50%距离,距离view的上边缘为50%距离,即正中心,具体每个含义见下面的具体属性介绍。
初始化 :
Animation operatingAnim = AnimationUtils.loadAnimation(this, R.anim.tip); LinearInterpolator lin = new LinearInterpolator(); operatingAnim.setInterpolator(lin);
开始旋转 :
if (operatingAnim != null) { infoOperatingIV.startAnimation(operatingAnim); //infoOperatingIV 图片id
}
停止旋转 :
if (operatingAnim != null) { infoOperatingIV.startAnimation(operatingAnim); //infoOperatingIV 图片id
}
二 , 渐变动画
首先是AlphaAnimation。alpha_anim.xml:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.1" android:toAlpha="1.0" android:duration="2000" /> </set>
alphaAnimation = AnimationUtils.loadAnimation(this.getContext(), R.anim.alpha_anim);
二 ,缩放动画 ScaleAnimation
scale_anim.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="0.0" android:toYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:fillAfter="false" android:duration="500" /> </set>
scaleAnimation = AnimationUtils.loadAnimation(this.getContext(), R.anim.scale_anim);
三,旋转动画 rotate_anim.xml:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%" android:duration="500" /> </set>
rotateAnimation = AnimationUtils.loadAnimation(this.getContext(), R.anim.rotate_anim);
四 ,平移动画
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="10" android:toXDelta="100" android:fromYDelta="10" android:toYDelta="100" /> </set>
相关文章推荐
- android 蓝牙学习资料
- Android ORMLite数据库简介
- Android Property Animation 物业动画
- android:gravity和android:layout_gravity的区别
- 为什么Android手机越用越慢
- android的崩溃报告(crash dump)
- Android平台调用WebService详解
- Android-Universal-Image-Loader加载图片
- Android 应用内切换语言
- Android开发之WebService介绍
- The Toast in android
- Android—jar包存在,编译无错,运行有错java.lang.NoClassDefFoundError:dao.master....
- Android命令行工具logcat详细用法!
- Android中利用代码去除标题栏
- Android中使用GSON包解析JSON数据(复杂JSON)
- Android中程序与Service交互的方式——综述
- Android应用的电量消耗和优化的策略
- Android Studio 使用笔记:查看类结构和继承关系
- 问题"trouble processing "一个可能的解决方法
- Android 定时任务