码迷,mamicode.com
首页 > 其他好文 > 详细

补间动画Tween

时间:2015-12-04 20:41:19      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

1.透明度渐变动画(AlphaAnimation)

1)纯代码实现

Animation animation = new AlphaAnimation(1f,0.1f);

参数1: 起始透明度;

参数2: 目标透明度;

//实现渐变功能
            AnimationSet aset = new AnimationSet(true);
            
            AlphaAnimation alpha = new AlphaAnimation(1, 0); // 由完全显示 -->// 完全透明
            alpha.setDuration(3000); // 3秒完成动画            
            aset.addAnimation(alpha); // 增加动画
            MainActivity.this.img.startAnimation(aset); // 启动动画

2)xml文件实现(res文件下新建anim文件下新建xml)

xml:

<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
    android:repeatMode="restart"
     android:repeatCount="3" 
     android:duration="500" 
     android:fromAlpha="1"
     android:toAlpha="0">
    

</alpha>
</set>

java:

Animation anim = AnimationUtils.loadAnimation(MainActivity.this,
                    R.anim.alpha);
            MainActivity.this.img.startAnimation(anim); // 启动动画

2.旋转

Animation animation  = new RotateAnimation(360,0,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); 

参数1:旋转的起始角度

参数2:旋转的终止角度

参数3:旋转中心的x轴取值参照方式

参数4:中心点x轴的取值

参数5:旋转中心的y轴取值参照方式

参数6:中心点y轴的取值

1)纯代码实现

    AnimationSet rset = new AnimationSet(true);
                RotateAnimation rotate = new RotateAnimation(
                        0,360 ,    // 0~360度
                        Animation.RELATIVE_TO_PARENT,0.5f ,    // X轴开始位置
                        Animation.RELATIVE_TO_PARENT,0.0f );    // Y轴移动位置
                rotate.setDuration(3000); // 3秒完成动画
                rset.addAnimation(rotate); // 增加动画
                
                MainActivity.this.image.startAnimation(rset); // 启动动画

2)xml实现

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <rotate
        android:fromDegrees="0.0"
        android:toDegrees="+360.0"
        android:pivotX="50%p"
        android:pivotY="0%p"
        android:duration="3000" />
</set>

3.缩放

Animation animation  = new 

ScaleAnimation(1f,0.2f,1f,0.2f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); 

参数1:x方向起始大小(1f表示原图大小)

参数2:x方向终止大小(0.2f表示原图的0.2倍)

参数3:y方向起始大小(1f表示原图大小)

参数4:y方向终止大小(0.2f表示原图的0.2倍)

参数5:缩放中心点x轴取值的参照方式

参数6:中心点x轴的取值(0.5f表示相对与原图的0.5倍)

参数7:缩放中心点y轴取值参照方式

参数8:中心点y轴的取值(0.5f表示相对与原图的0.5倍)

 

1)代码实现

//实现缩放功能
                AnimationSet sset = new AnimationSet(true);
                
                ScaleAnimation scale = new ScaleAnimation(1, 0.0f, 1, 0.0f,
                        Animation.RELATIVE_TO_SELF, 0.5f,
                        Animation.RELATIVE_TO_SELF, 0.5f);
                scale.setDuration(3000); // 3秒完成动画
                sset.addAnimation(scale); // 增加动画
                MainActivity.this.image.startAnimation(sset); // 启动动画

2)xml实现

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:fromXScale="1.0"
        android:toXScale="0.0"
        android:fromYScale="1.0"
        android:toYScale="0.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:startOffset="100"
        android:repeatCount="3"
        android:duration="3000" />
</set>

4.平移动画

Animation  animation = new TranslateAnimation(0,50,0,50);

参数1:x轴的起始位置

参数2:x轴的终止位置

参数3:  y轴的起始位置

参数4:y轴的终止位置

1)代码实现

//实现移动
                AnimationSet tset = new AnimationSet(true);
                TranslateAnimation tran = new TranslateAnimation(
                        Animation.RELATIVE_TO_SELF,0.0f ,    // X轴开始位置
                        Animation.RELATIVE_TO_SELF,0.5f ,    // X轴移动的结束位置
                        Animation.RELATIVE_TO_SELF,0.0f ,    // Y轴开始位置
                        Animation.RELATIVE_TO_SELF,0.5f );    // Y轴移动位置
                tran.setDuration(3000); // 3秒完成动画
                tset.addAnimation(tran); // 增加动画
                MainActivity.this.image.startAnimation(tset); // 启动动画

2)xml实现

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromXDelta="0.0"
        android:toXDelta="50%"
        android:fromYDelta="0.0"
        android:toYDelta="150%"
        android:duration="3000" />
</set>

5.混合动画

1)代码实现

    AnimationSet tset = new AnimationSet(true);
                
                aset=new AnimationSet(true);
                 AlphaAnimation alph=new AlphaAnimation(0, 1);
                 alph.setRepeatCount(3);
                  alph.setDuration(5000);
                 aset.addAnimation(alph);
                 
                TranslateAnimation tran = new TranslateAnimation(
                Animation.RELATIVE_TO_SELF,0.0f ,    // X轴开始位置
                Animation.RELATIVE_TO_SELF,0.5f ,    // X轴移动的结束位置
                Animation.RELATIVE_TO_SELF,0.0f ,    // Y轴开始位置
                Animation.RELATIVE_TO_SELF,0.5f );    // Y轴移动位置
        tran.setDuration(3000); // 3秒完成动画
        
        tset.addAnimation(alph); // 增加动画
                tset.addAnimation(tran); // 增加动画
                
                MainActivity.this.image.startAnimation(tset); // 启动动画

2)xml配置实现

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromXDelta="0.0"
        android:toXDelta="50%"
        android:fromYDelta="0.0"
        android:toYDelta="150%"
        android:duration="3000" />
    <scale
        android:fromXScale="1.0"
        android:toXScale="0.0"
        android:fromYScale="1.0"
        android:toYScale="0.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:startOffset="100"
        android:repeatCount="3"
        android:duration="3000" />
</set>

 

补间动画Tween

标签:

原文地址:http://www.cnblogs.com/GroveWang/p/5020220.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!