Android Scale Animation with bounce interpolator

前端 未结 4 671
无人及你
无人及你 2020-12-12 22:50

I am doing a scale animation with anim xml as follows. The animation interpolator isn\'t working. I am trying to have bounce interpolator but isn\'t working.

相关标签:
4条回答
  • 2020-12-12 23:15

    Finally got the solution. It works for me and could be helpful to others. The key was to put the android:interpolator tag in the animation set.

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/bounce_interpolator" >
    
    <scale
        android:duration="600"
        android:fromXScale="1"
        android:fromYScale="0.5"
        android:pivotX="50%"
        android:pivotY="0%"
        android:toXScale="1.0"
        android:toYScale="1.0" />
    
    <alpha
        android:duration="600"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />
    
    </set>
    
    0 讨论(0)
  • 2020-12-12 23:22

    Bounce is just an animation effect where animation ends in bouncing fashion. For this set android:interpolator value to @android:anim/bounce_interpolator. This bounce can be used with any kind animation. Following slide down example uses bounce effect.

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true"
    android:interpolator="@android:anim/bounce_interpolator">
    
    <scale
        android:duration="500"
        android:fromXScale="1.0"
        android:fromYScale="0.0"
        android:toXScale="1.0"
        android:toYScale="1.0" />
    

    0 讨论(0)
  • try to add a duration :

    <set xmlns:android="http://schemas.android.com/apk/res/android" >
    
    <scale 
      android:fromXScale="1"
      android:fromYScale="0.5"
      android:interpolator="@android:anim/bounce_interpolator"
      android:pivotX="50%"
      android:pivotY="0%"
      android:toXScale="1.0"
      android:toYScale="1.0"
      android:duration="1000" />
    </set>
    

    And note that the animation set is useless if it contains only one animation.

    0 讨论(0)
  • 2020-12-12 23:33

    If you want to have different interpolators for your animations in the animation set, set the shareInterpolator attribute to false like this:

    <set xmlns:android="http://schemas.android.com/apk/res/android"
         android:shareInterpolator="false">
    

    And then set an interpolator in each animation element. Apparently, shareInterpolator is set to true by default.

    0 讨论(0)
提交回复
热议问题