活动android之间的自定义转换

San*_*dra 3 android transition android-activity

我正在构建一个Android应用程序,我希望能够从一个活动到另一个活动进行自定义转换.当我按下第一个活动上的按钮时,我希望它减小其大小并转到屏幕的一个角落,直到它消失,然后调用第二个活动.当然,在调整大小和移动第一个活动期间,第二个活动将开始显示自己(我想说的是,在此期间,我不想在下面有黑屏).有人有这种东西的经验吗?我还要注意,我正在为API 3.0+构建我的应用程序,因此可以使用更新的函数和方法.谢谢!

Mic*_*ley 14

您应该能够使用简单的比例动画.在第二个活动中,您可以执行以下操作:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    overridePendingTransition(R.anim.scale_from_corner, R.anim.scale_to_corner);
}
Run Code Online (Sandbox Code Playgroud)

对于动画,它将是:

scale_to_corner.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale android:fromYScale="1.0" android:toYScale="0"
        android:fromXScale="1.0" android:toXScale="0" 
        android:duration="500"/>
</set>
Run Code Online (Sandbox Code Playgroud)

和scale_from_corner.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale android:fromYScale="0" android:toYScale="1.0"
        android:fromXScale="0" android:toXScale="1.0" 
        android:duration="500" android:pivotX="100%"
        android:pivotY="100%" />
</set>
Run Code Online (Sandbox Code Playgroud)

这将使您的第一个活动缩小到左上角,而您的第二个活动从右下角开始增长.如果要更改它们从中缩小或缩小的点,可以只更改pivotX和pivotY.