简体   繁体   中英

Center view during simple scale animation

I'm trying to do a scale in/out animation for activity/framgent transition

here are the two animations :

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator" >

    <scale
        android:fromXScale="80%"
        android:fromYScale="80%"
        android:toXScale="80%"
        android:toYScale="80%" />

    <alpha
        android:fromAlpha="1.0"
        android:toAlpha="0.5" />

</set>

-

<?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="500"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator" >

        <translate
            android:fromXDelta="100%"
            android:fromYDelta="0"
            android:toXDelta="0"
            android:toYDelta="0" />

</set>

Use it like that :

overridePendingTransition(R.anim.slide_in_right, R.anim.slide_to_behind);

The problem is that the activity doesn't scale down in the center of the screen, it stick to the top/left of the screen

Any idea what wm i missing ? Or doing wrong ?

Add a pivot to your scale animation. Add this on your xml:

    android:pivotX="50%"
    android:pivotY="50%"

Your scale should look like:

  <scale
    android:fromXScale="100%"
    android:fromYScale="100%"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="80%"
    android:toYScale="80%" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM