Transition animation使用笔记

  • -
Material Design设计语言动画篇共推出六种类型的动画效果:

1、Touch feedback(触摸反馈) 
2、Reveal effect(揭露效果) 
3、Activity transitions(Activity转换效果) 
4、Curved motion(曲线运动) 
5、View state changes (视图状态改变) 
6、Animate Vector Drawables(矢量动画)
安卓5.0后提供了一个过度动画框架,而且transition框架是基于属性 动画实现的,transition框架是对属性动
画的一种封装,transition框架提供的api可以简单的实现很复杂的属性动画效果,
  一 **转场动画**
    xml定义方式
                <?xml version="1.0" encoding="utf-8"?>
                 <transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
                   <explode android:duration="2000"/>
                    </transitionSet>   
 记得style.xml文件中加入
         <itemname="android:windowEnterTransition">@transition/activity_explode.xml</item>

   2代码中实现方式
   // 允许使用transitions  在setlayout之前使用
   getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS); 
   也可以在style.xml文件中加入
    <item name="android:windowEnterTransition">true</item>  
    主Activity
    @Override
       protected void onCreate(@Nullable Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
         setContentView(R.layout.threelayout);
           getWindow().setEnterTransition(new Explode().setDuration(2000));//分解
           getWindow().setEnterTransition(new Fade().setDuration(2000));//淡入淡出效果
            getWindow().setExitTransition(new Slide().setDuration(2000));//滑入效果
            //下面这两个效果与上面进入和退出的效果对应的,
            如果没有设置将执行进入或者退出的反向动画效果
            //再次进入的效果动画与setExitTransition对应
          getWindow().setEnterTransition(new Fade().setDuration(5000));
        //返回的动画效果 与setEnterTransition对应
           getWindow().setReenterTransition(new Fade().setDuration(2000));
       }
       //设置点击事件  
       Intent intent4 = new Intent(MainActivity.this, DetialActivity.class);
                       startActivity(intent4, ActivityOptions.makeSceneTransitionAnimation(MainActivity.this).toBundle());

   在第二个activity中可以设置进入的动画和返回的动画效果

    getWindow().setEnterTransition(new Explode().setDuration(2000));//分解
   // getWindow().setEnterTransition(new Fade().setDuration(2000));
   //淡入淡出效果 
   //getWindow().setEnterTransition(new Slide().setDuration(2000));
   //   可以设置退出效果动画  
   getWindow().setReenterTransition(new Fade().setDuration(2000));

   **2.Activity间的共享元素** 
   Transition框架知道用适当的动画向用户展示从一个view向另外
   一个view过度。 
   设置共享属性名字 两个共享view设置一样  
   android:transitionName="mybutton"
   Intent intent3 = new Intent(MainActivity.this, ThreeActivity.class);
                       startActivity(intent3, ActivityOptions.makeSceneTransitionAnimation(MainActivity.this,
   button3, "mybutton").toBundle());
   多个共享属性设置方式
   ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this,  
        Pair.create(view1, "mybutton"),  
        Pair.create(view2, "mybutton"));  
     二*Reveal effect(揭露效果)** 
                  view - 需要显示揭露动画的View
                  centerX - 动画开始的X轴坐标
                  centerY - 动画开始的Y轴坐标
                  startRadius - 动画开始时的半径
                  endRadius - 动画结束时的半径
                    Animator animator = ViewAnimationUtils.createCircularReveal(button1, button1.getWidth() / 2, button1.getHeight() / 2, 0, button1.getHeight());
                    animator.setDuration(500);
                    animator.setInterpolator(new AccelerateInterpolator());
                    animator.start();
                    animator.addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            super.onAnimationEnd(animation);
                            Intent intent5 = new Intent(MainActivity.this, FvieActivity.class);
                            startActivity(intent5);
                        }
                    });
                    //揭露动画2
                    float hypot = (float) Math.hypot(button5.getWidth(), button5.getHeight());//勾股定理以斜边为结束的半径
                    Animator animator1 = ViewAnimationUtils.createCircularReveal(button5, button5.getWidth(), 0, 0, hypot);
                    animator1.setDuration(500);
                    animator1.setInterpolator(new AccelerateInterpolator());
                    animator1.start();
                    animator1.addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            super.onAnimationEnd(animation);
                            Intent intent5 = new Intent(MainActivity.this, SixActivity.class);
                            startActivity(intent5);
                        }
                    });
   **三,扩张动画**
                     /**
                     *@source - The View that the new activity is animating from,界面是从哪个视图上开始扩张
                     *@startX - 开始扩张的x坐标
                     *@startY - 开始扩张的y坐标
                     *@startWidth - 扩张完后Activity的宽度(为0表示全屏)
                     *@startHeight - 扩张完后Activity的高度(为0表示全屏)
                     */
                    Intent intent6 = new Intent(MainActivity.this, SevenActivity.class);
                    ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeScaleUpAnimation(button6, button6.getWidth()/2, button6.getHeight()/2, 0, 0);
                    startActivity(intent6, optionsCompat.toBundle())

     返回时调用
     @Override
    protected void onDestroy() {
        super.onDestroy();
    finishAfterTransition();

    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值