Android 过渡动画(Transition)

在Android5.0之前,如果我们需要改变默认的Activity切换动画。可能需要在startActivity()之后,添加一个overridePendingTransition()方法。overridePendingTransition()
摘要由CSDN通过智能技术生成

使用过渡动画为布局的变化添加动画效果(场景过渡动画)

为布局的变化添加动画效果大概需要以下几个流程:
1.为起始布局和结束布局个创建一个Scene(场景)对象。然而大部分情况下,我们不需要创建起始布局的Scene对象,因为起始布局的场景通常是根据当前布局自动确定的。
2.创建一个Transition对象来定义所需的动画类型。
3.调用TransitionManager.go(),系统会运行动画以交换布局。

创建场景
我们可以直接从布局文件中创建Scene实例。调用Scene.getSceneForLayout()。该方法接受三个参数,第一个参数是场景所在的ViewGroup,第二个参数是场景的布局文件ID,第三个参数是一个Context对象。
比如Activity布局文件如下:res/layout/activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">    
    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        ...>
    </androidx.appcompat.widget.Toolbar>   
    <FrameLayout
        android:id="@+id/scene_root"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar">
    </FrameLayout>     
</androidx.constraintlayout.widget.ConstraintLayout>

第一个场景布局文件如下:res/layout/a_scene.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值