zoukankan      html  css  js  c++  java
  • Android开发属性动画

    普通动画效果和属性动画效果区别:

    普通动画效果的动画播放后只是产生了视觉欺骗,并没有移动真实的控件。

    属性动画直接真实的移动控件

    AnimationSet动画:

    TextView t1 = (TextView)findViewById(R.id.textView6);
    TextView t2 = (TextView)findViewById(R.id.textView7);        
    
    //设置移动
    AnimationSet animationSet = new AnimationSet(true);
    TranslateAnimation translateAnimation = new TranslateAnimation(
              Animation.RELATIVE_TO_SELF,0f,
             Animation.RELATIVE_TO_SELF,-2f,
             Animation.RELATIVE_TO_SELF,0f,
             Animation.RELATIVE_TO_SELF,0f
    );
    //设置透明度
    AlphaAnimation alphaAnimation = new AlphaAnimation(1,0);
    //添加进去
    animationSet.addAnimation(translateAnimation);
    animationSet.addAnimation(alphaAnimation);
    animationSet.setDuration(500);
    t1.startAnimation(animationSet);
    t1.setVisibility(View.GONE);

    属性动画:

    RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.foot);
    
                float curTranslationY = relativeLayout.getTranslationY();
                ObjectAnimator animator = ObjectAnimator.ofFloat(relativeLayout, "translationY", curTranslationY, -300f);
                animator.setDuration(200);
                animator.start();

     总的来说属性动画执行的动画效果后控件的位置也会发生改变,解决了很多麻烦。

    ObjectAnimator animator = ObjectAnimator.ofFloat(relativeLayout, "translationY", curTranslationY, -300f);

    这里的4个参数分别代表的是

    1.要进行操作的控件

    2.执行的动画效果,我这里的是沿着Y移动 translationX 是沿着X轴移动 rotationX 就是旋转了

    至于后面的几个参数就是移动的位置了如果添加第5个参数那么 3 - 5 的参数代表的就是 (从第3个参数移动到第4个参数,然后返回到第5个参数)

    ObjectAnimator animator = ObjectAnimator.ofFloat(relativeLayout, "translationY", curTranslationY, -300f,curTranslationY);

    上面的代码代表的就是从curTranslationY开始移动 移动到 -300f 然后 返回到 curTranslationY 的位置。

    animator.setDuration(200);
    animator.start();

    上面第一行代码代表整个动画执行的时间,这里是200毫秒。

    最后一行代码开始执行动画效果。

  • 相关阅读:
    BestCoder6 1002 Goffi and Squary Partition(hdu 4982) 解题报告
    codeforces 31C Schedule 解题报告
    codeforces 462C Appleman and Toastman 解题报告
    codeforces 460C. Present 解题报告
    BestCoder3 1002 BestCoder Sequence(hdu 4908) 解题报告
    BestCoder3 1001 Task schedule(hdu 4907) 解题报告
    poj 1195 Mobile phones 解题报告
    二维树状数组 探索进行中
    codeforces 460B Little Dima and Equation 解题报告
    通过Sql语句控制SQLite数据库增删改查
  • 原文地址:https://www.cnblogs.com/adversary/p/5285562.html
Copyright © 2011-2022 走看看