两个Activity无缝上下切换的思路。

A–>B

        Intent intent = new Intent(A.this,B.class);
        startActivity(intent);
        overridePendingTransition( R.anim.slide_from_top, R.anim.slide_to_bottom);

B–>A(finish)

@Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
        overridePendingTransition(R.anim.slide_from_bottom, R.anim.slide_to_top);
    }

四个动画:

slide_from_top.xml


<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="300"
        android:fromYDelta="100%p"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:toYDelta="0" />
set>

slide_to_bottom.xml


<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="300"
        android:fromYDelta="0"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:toYDelta="0%p" />
set>

slide_from_bottom.xml


<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="300"
        android:fromYDelta="0%p"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:toYDelta="0" />

set>

slide_to_top.xml


<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="300"
        android:fromYDelta="0"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:toYDelta="100%p" />

set>

你可能感兴趣的:(android随笔)