Android过渡动画基础使用

本文介绍了Android API19引入的Transition过渡动画框架,讲解了基础使用、延迟动画、Activity切换动画以及如何自定义动画。通过示例展示了如何创建场景、设置延迟动画、实现Activity平滑切换以及创建共享元素动画,帮助开发者实现更丰富的UI交互效果。
摘要由CSDN通过智能技术生成

前言

Android从API19引入了Transition过渡动画框架,它通过场景Scene概念来表述动画的关键帧,只要提供了开始和结束场景的内容就会自动做动画。过渡动画其实是对属性动画的一种封装,它能够一次对多个对象做动画而不需要特别复杂的配置。除此之外Activity之间的切换效果也可以使用过渡动画来实现。

基础使用

首先需要定义Scene也就是场景对象,场景其实就是某个事件点所有的视图对象当前状态,这里先定义一个开始的场景。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="300dp">

    <ImageView
        android:id="@+id/first"
        android:background="@drawable/round_red"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="50dp"
        android:layout_gravity="top|left"
        android:layout_width="100dp"
        android:layout_height="100dp" />

    <ImageView
        android:id="@+id/second"
        android:background="@drawable/round_green"
        android:layout_marginTop="20dp"
        android:layout_marginRight="50dp"
        android:layout_gravity="top|right"
        android:layout_width="100dp"
        android:layout_height="100dp" />

    <ImageView
        android:id="@+id/third"
        android:layout_gravity="bottom|left"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="50dp"
        android:background="@drawable/round_yellow"
        android:layout_width="100dp"
        android:layout_height="100dp" />

    <ImageView
        android:id="@+id/forth"
        android:layout_gravity="bottom|right"
        android:layout_marginBottom="20dp"
        android:layout_marginRight="50dp"
        android:background="@drawable/round_blue"
        android:layout_width="100dp"
        android:layout_height="100dp" />
</FrameLayout>
scene1 = Scene.getSceneForLayout(mContainer, R.layout.scene_layout_one, this);

场景第一参数mContainer就是包含这个场景的根布局,后面的场

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值