android 动画

tween



xml 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false">


    <!-- 透明动画 -->


    <alpha 
        android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:duration="5000"/> 

 


    <!-- 旋转动画效果 -->
    <rotate
        android:duration="5000"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="90" />

   <scale 
            android:fromXScale="1.4"  
            android:toXScale="0.0" 
            android:fromYScale="0.6" 
            android:toYScale="0.0"  
            android:pivotX="50%"  
            android:pivotY="50%"  
            android:duration="5000" /> 


<translate 
        android:fromXDelta="0" 
        android:fromYDelta="0" 
        android:toXDelta="100" 
        android:toYDelta="100" 
        android:duration="5000" /> 
    
</set>

/**
 

* 1 propertyAnimation

* 2 viewAnimation

* 2.1tween animation

* 常用的几种动画有:

* alpha透明动画效果

* android:fromAlpha

* Float. Starting opacity offset, where 0.0 is transparent and 1.0 is opaque.

* android:toAlpha

* Float. Ending opacity offset, where 0.0 is transparent and 1.0 is opaque.

* scale缩放动画效果

* translate平移动画效果

* rotate旋转动画效果
*/


@SuppressWarnings("unused")
private void tweenAnim() {


// 方式一: xml方式定义,放在res/anim/xxx.xml
// Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha);
// img_main.startAnimation(animation);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump);
img_main.startAnimation(animation);
// 方式二:代码实现
// Animation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
// img_main.startAnimation(alphaAnimation);


// 其他效果同上
}

frame

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
    <item android:drawable="@drawable/rocket_thrust1" android:duration="200" />
    <item android:drawable="@drawable/rocket_thrust2" android:duration="200" />
    <item android:drawable="@drawable/rocket_thrust3" android:duration="200" />
</animation-list>


ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
rocketImage.setBackgroundResource(R.drawable.rocket_thrust);

rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
rocketAnimation.start();



posted @ 2012-10-25 17:05  retacn_yue  阅读(152)  评论(0编辑  收藏  举报