Android动画

我们使用Scene来展示动画。
首先我们获取场景,代码如下:

Scene scene1 = Scene.getSceneForLayout(frameLayout, R.layout.animations_scenes1, this);

frameLayout为盛放控件的总容器。
animations_scenes1为盛放控件。
this为上下文。

我们写四个scene布局:
animations_scenes1代码如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="20dp">

    <ImageView
        android:id="@+id/iv_green"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="@color/theme_green_primary"/>

    <ImageView
        android:id="@+id/iv_red"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentRight="true"
        android:background="@color/theme_red_primary"/>

    <ImageView
        android:id="@+id/iv_blue"
        android:layout_marginTop="20dp"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_below="@id/iv_red"
        android:background="@color/theme_blue_primary"/>

    <ImageView
        android:id="@+id/iv_yellow"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_below="@id/iv_green"
        android:layout_alignParentRight="true"
        android:layout_marginTop="20dp"
        android:background="@color/theme_yellow_primary"/>
</RelativeLayout>

animations_scenes2 -- 4 置换ImageView的位置。要注意的是四个布局的id要一直,这样动画就可以在同id的控件间传动。

下面是动画转换的资源文件slide_and_changebounds_sequential_with_interpolators.xml:

<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"
               android:duration="500"
               android:transitionOrdering="sequential">
    <slide android:interpolator="@android:interpolator/decelerate_cubic"/>
    <changeBounds android:interpolator="@android:interpolator/bounce"/>
</transitionSet>

最后调用方法转换:

TransitionManager.go(scene1, TransitionInflater.from(AnimationsActivity2.this).inflateTransition(R.transition.slide_and_changebounds_sequential));
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 前不久,我写了篇关于Activity之间的过渡跳转的文章(有兴趣的请戳 Android动画 —— Activity...
    王可大虾阅读 1,099评论 0 6
  • Animation Animation类是所有动画(scale、alpha、translate、rotate)的基...
    四月一号阅读 1,952评论 0 10
  • 【Android 动画】 动画分类补间动画(Tween动画)帧动画(Frame 动画)属性动画(Property ...
    Rtia阅读 6,289评论 1 38
  • Android 动画总结(1) - 概述Android 动画总结(2) - 帧动画Android 动画总结(3) ...
    三流之路阅读 825评论 0 3
  • 动画基础概念 动画分类 Android 中动画分为两种,一种是 Tween 动画、还有一种是 Frame 动画。 ...
    Rtia阅读 1,279评论 0 6