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

animation- 动画效果实现(代码中)

时间:2015-03-20 21:51:05      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:

1,首先我们看一下如下的代码

import android.view.animation.LayoutAnimationController;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.Transformation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.TranslateAnimation;


    private Animation myHistoryAnimation;
    private LayoutAnimationController myLayoutControl;
    private AlphaAnimation myHistoryAlphaAnimation;
    private AlphaAnimation myHistoryAlphaAnimationConTime;
    private TranslateAnimation myHistoryTranslateAnimation;
    private AnimationSet myHistoryAnimationSet;



myHistoryAlphaAnimation = new AlphaAnimation(1, 0);
        myHistoryAlphaAnimationConTime = new AlphaAnimation(1, 1);
        myHistoryAlphaAnimation.setDuration(1000);
        myHistoryAlphaAnimationConTime.setDuration(500);
        myHistoryAnimationSet = new AnimationSet(true);
/* Vanzo:zhangshuli on: Fri, 20 Mar 2015 14:57:37 +0000
 * modify for v5 calculator
        myHistoryTranslateAnimation = (TranslateAnimation) AnimationUtils.loadAnimation(
                this, R.anim.history_clear_anim);
 */
        myHistoryTranslateAnimation = new TranslateAnimation(

                Animation.RELATIVE_TO_SELF,0f,

                Animation.RELATIVE_TO_SELF,0f,

                Animation.RELATIVE_TO_SELF,0f,

                Animation.RELATIVE_TO_SELF,10f);
        myHistoryTranslateAnimation.setDuration(1000);
// End of Vanzo: zhangshuli
        myHistoryAnimationSet.setFillAfter(true);
myHistoryAnimationSet.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation arg0) {
            // TODO Auto-generated method stub
                history_clear_choose.setVisibility(View.GONE);

            }

            @Override
            public void onAnimationRepeat(Animation arg0) {
            // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationEnd(Animation arg0) {
            // TODO Auto-generated method stub
            android.util.Log.e("zhangshuli", "set");
/* Vanzo:zhangshuli on: Fri, 20 Mar 2015 16:17:24 +0000
 * modify for v5 calculator
                if (mDrawerLayout.isDrawerVisible(GravityCompat.END)) {
                    mDrawerLayout.closeDrawer(GravityCompat.END);
                }
 */
// End of Vanzo: zhangshuli

            }
        });
        myHistoryAlphaAnimation.setAnimationListener(new AnimationListener() {

                @Override
            public void onAnimationStart(Animation arg0) {
            // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationRepeat(Animation arg0) {
            // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationEnd(Animation arg0) {
 mHistory.clear();
                mLogic.onClear();
                android.util.Log.e("zhangshuli", "tran1");

            }
        });
        myHistoryAnimationSet.addAnimation(myHistoryTranslateAnimation);
        myHistoryAnimationSet.addAnimation(myHistoryAlphaAnimation);
        myHistoryAnimationSet.addAnimation(myHistoryAlphaAnimationConTime);
        myLayoutControl = new LayoutAnimationController(myHistoryAnimationSet);
        myLayoutControl.setDelay(0.1f);
       // myLayoutControl.setOrder(LayoutAnimationController.ORDER_NORMAL);
        myLayoutControl.setOrder(LayoutAnimationController.ORDER_REVERSE);

 mHistoryDisplayList.setLayoutAnimation(myLayoutControl);

2.从以上的代码中我们可以发现。代码中定义动画的话,有个好处,就是比较灵活,可以根据我们的需要动态的更改动画的时间等属性。当然,你也会看到它代码的重用性非常的糟糕。

1)创建动画:其实就是new一个相应的动画就行了

2)然后就是设置动画的属性值,时间等

   import android.view.animation.AlphaAnimation;   

  AlphaAnimation alphaAnimation=new AlphaAnimation( 1f,0.5f); //动画时间 alphaAnimation.setDuration(1000); //动画结束以后是否应用,false的话,会返回初始位置 alphaAnimation.setFillAfter(true); //设置动画动作样式 alphaAnimation.setInterpolator(this,android.R.anim.accelerate_decelerate_interpolator);

其他的也类似

import android.view.animation.Animation;
import android.view.animation.TranslateAnimation; 
    TranslateAnimation translateAnimation = new TranslateAnimation(
            //第一个参数:相对于父类还是自身比例 第二个其实x坐标
            Animation.RELATIVE_TO_SELF, 0f,
            //起始y坐标
            Animation.RELATIVE_TO_SELF,0f,
            //结束x坐标
            Animation.RELATIVE_TO_SELF,0f,
            //结束y坐标
            Animation.RELATIVE_TO_SELF,10f);

 

 

3)如果你仅仅就需要一个简单的动画,那么你只需要

animation- 动画效果实现(代码中)

标签:

原文地址:http://www.cnblogs.com/zhangshuli-1989/p/4354481.html

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