How to create android wipe transition between two

2019-03-26 15:18发布

问题:

I am trying to create a transition animation in an Android application to change between two layouts. I've tried to search about animation transition, but only fade transition, slide transition, bounce, etc. I can't find one for wipe transition like transition at power point.

回答1:

Use ClipBound Property of view

Rect localRect = view.getVisibileRect();// or you can assign any required rectangle.

Rect rectFrom,rectTo;

Rect rectFrom = new Rect(localRect),rectTo = new Rect(localRect);

now adjust your both starting and ending rectangle according to requirement.

Animator animator = ObjectAnimator.ofObject(shape, "clipBounds", new RectEvaluator(), rectFrom, rectTo);

animator.start();


回答2:

in your activity execute the animation with the following:

This will do a top to bottom to top animation that you can easily manipulate to be horizontal. startActivityForResult(i,ACTIVITY_SLIDE);
overridePendingTransition(R.anim.bottom_in, R.anim.top_out);

top_out.xml, bottom_in.xml below... need to be separate files of course

<?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/linear_interpolator">
        <translate
            android:fromYDelta="100%p"
            android:toYDelta="0"
            android:duration="3000"/>
    </set>




<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator">
    <translate
        android:fromYDelta="0"
        android:toYDelta="-100%p"
        android:duration="3000"/>
</set>


回答3:

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <translate
            android:duration="700"
            android:fromXDelta="90%"
            android:toXDelta="0" />
    </set>


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="700"
        android:fromXDelta="5"
        android:toXDelta="100%" />
</set>