Material DesignAndroid知识Android开发

Android动画进阶Lollipop

2017-04-21  本文已影响196人  Rayhaha

Lollipop动画

Lollipop为我们带来不少动画,简单而有效,灵活运用提升APP逼格

过渡动画

Activity过渡动画包含两部分 :

  1. Activity的进入和退出
  2. 过渡过程中的共享元素

进入和退出

目标跳转Activity :

上述设置需要在setContentView() 之前设置

一共就是上述三种模式: ExplodeSlideFade

效果如图:

过渡动画演示.mp4_1492677049.gif

共享元素

效果图:

共享元素.mp4_1492769148.gif
  1. 需要共享的View 在两边的布局 加上 android:transitionName="one" 里面的值是自己定的一个标识,但是必须保持两边一致
  2. 在启动Activity中 找到 需要共享的控件并且设置好Tag就可以了(需要注意的传入的只能是View)
  3. 在跳转的目标Activity中设置方法:
  startActivity(mIntent,
       ActivityOptions.makeSceneTransitionAnimation(this,
     Pair.create(ivImageI, "one"), // 设置共享的控件和他的Tag 就可以了
    Pair.create(ivImageIi, "two"))
    .toBundle());

动画效果

Ripple (波纹效果)

十分简单在Xml中控件添加

这个是系统默认的
自定义Ripple同样简单,立即上手

  1. drawable文件夹新建一个Ripple资源文件
  2. 代码如下:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="#cb2eff" android:radius="500dp">
    <item android:drawable="@color/blue_i"/>
</ripple>
  1. android:background="@drawable/ripple_red"
  2. 这就是一个蓝色底,红色波纹的点击效果了

Circular Reveal

其实就是一个圆形路径绘制。
和Animator的使用基本一致
API解析:

两种应用:

  1. 控件点击的动画效果
  2. 页面过渡的动画 : 就是给顶布局 设置 Circular 动画

//设置顶布局过渡动画
 llRoot.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            //当布局已经完全展示出来再开始动画
            @Override
            public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                v.removeOnLayoutChangeListener(this);
                Animator circularReveal = ViewAnimationUtils.createCircularReveal(
                        llRoot,
                        llRoot.getWidth() / 2,
                        llRoot.getHeight() / 2,
                        50,
                       1000);
                circularReveal.setInterpolator(new AccelerateDecelerateInterpolator());
                circularReveal.setDuration(1000);
                circularReveal.start();
            }
        });

//     控件设置点击动画效果
        ivImageI.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //实现从左上角开始的扇形展开动画
                Animator circularReveal = ViewAnimationUtils.createCircularReveal(
                        ivImageI,
                        0,
                        0,
                        0,
                        ivImageI.getWidth()+159);
                circularReveal.setInterpolator(new AccelerateDecelerateInterpolator());
                circularReveal.setDuration(1000);
                circularReveal.start();
            }
        });  

效果图:

circularAnim.mp4_1492705069.gif

最后

Lollipop 中添加的动画效果还是十分不错的,而且使用也是十分简单高效
将有需求的动画效果封装在自己的基类文件中使用起来就更加顺畅了

如果觉有有用,可以点赞鼓励一下哈O(∩_∩)O~~
附上:代码Github

上一篇 下一篇

猜你喜欢

热点阅读