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


    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)如果你仅仅就需要一个简单的动画,那么你只需要在一个控件上start这个动画就行了,如下

    view.startAnimation(myAnimation_Alpha);

    4)如果你希望把几个动画进行复合,这时候你需要借助

    myHistoryAnimationSet = new AnimationSet(true);
     myHistoryAnimationSet.addAnimation(myHistoryTranslateAnimation);

    AnimationSet 其实就相当于一个动画容器,可以把不同的动画效果合为一个复合动画进行

  • 相关阅读:
    pycharm试用版过期问题解决方法(仅能再使用30天)
    使用postmancli工具管理Postman数据
    使用Postman持续更新同步Collection
    ES6的解构赋值
    DOTween添加Sequance回调
    unity升级项目的时候注意不要忽略过程中的报错
    Java 如何实现各进制之间的相互转换
    使用 ohmyposh 美化 windows terminal,让其接近ohmyzsh
    configure: error: cannot find MySQL header files under /usr/local/mysql/lib/
    CentOS 7 释放内存
  • 原文地址:https://www.cnblogs.com/zhangshuli-1989/p/zhangshuli_anim_150318194.html
Copyright © 2020-2023  润新知