动画
来源:互联网 发布:java 单元测试框架 编辑:程序博客网 时间:2024/05/11 11:14
一、介绍:
二、实现方法
1、通过布局文件来实现
1)新建/res/anim/alpha.xml文件(这里以透明度动画为例子)
2)在MainActivity中写上
Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha);animation.setFillAfter(true);iv.startAnimation(animation);
这是便能实现动画效果了。。。。。
以下列出各种动画的常见配置:
1)alpha(透明度)
<alpha xmlns:android="http://schemas.android.com/apk/res/android" android:fromAlpha="1.0" android:toAlpha="0" android:duration="2000"></alpha>
2)rotate(旋转度)
<rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:toDegrees="90" android:pivotX="50%" android:pivotY="50%" android:duration="2000"></rotate>
3)scale(缩放)
<scale xmlns:android="http://schemas.android.com/apk/res/android" android:fromXScale="1.0" android:toXScale="2.0" android:fromYScale="1.0" android:toYScale="0.5" android:duration="2000"></scale>
4)translate(移动)
<translate xmlns:android="http://schemas.android.com/apk/res/android" android:fromXDelta="1.0" android:toXDelta="100.0" android:fromYDelta="1.0" android:toYDelta="100.0" android:duration="2000"></translate>
5)set(综合)
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" > <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="2000" android:fromAlpha="1.0" android:toAlpha="0" > </alpha> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="2000" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="90" > </rotate> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:duration="2000" android:fromXScale="1.0" android:fromYScale="1.0" android:toXScale="2.0" android:toYScale="0.5" > </scale> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="2000" android:fromXDelta="1.0" android:fromYDelta="1.0" android:toXDelta="100.0" android:toYDelta="100.0" > </translate></set>
以上所用到的命名空间可以在Android的官网中找到。
查找方法:android官网--------->>API Guides -------->>App resources ------------>>resources type
--------------->>animation
2、直接通过代码来实现动画
如:
Animation animation = new AlphaAnimation(1.0f, 0.0f);animation.setDuration(2000);animation.setFillAfter(true);iv.startAnimation(animation);