【问题标题】:Bounce button on tap点击弹跳按钮
【发布时间】:2013-02-21 15:45:07
【问题描述】:

有人知道是否有任何 xml 动画可以使按钮弹跳几秒钟。如果你可以分享一些例子......

【问题讨论】:

    标签: android android-animation android-button


    【解决方案1】:

    这是一个使用 ObjectAnimator 的简单方法。如果你想让它在蜂窝之前工作,你可以使用相同的语法并使用view animation 来完成,或者使用NineOldAndroids.

    ObjectAnimator animY = ObjectAnimator.ofFloat(button, "translationY", -100f, 0f);
    animY.setDuration(1000);//1sec
    animY.setInterpolator(new BounceInterpolator());
    animY.setRepeatCount(numRepeats);
    animY.start();
    

    【讨论】:

    • 我们怎样才能将此动画添加到多个按钮,.?居然按钮一个接一个掉下来。?
    • 添加 animY.setRepeatMode(ValueAnimator.REVERSE);.看起来更漂亮更光滑
    【解决方案2】:
        <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="0.5"
            android:toXScale="1.0"
            android:fromYScale="0.5"
            android:toYScale="1.0"
            android:pivotX="50%"
            android:pivotY="50%" />
    </set>
    

    上面的动画代码放在 anim 文件夹中,并使用 java 代码将其设置为任何视图:

    Animation animation = AnimationUtils.loadAnimation(this,R.anim.bounce);
    textview.startAnimation(animation);
    

    【讨论】:

      【解决方案3】:

      使用ViewPropertyAnimator 查看here 的一些示例动画。如果你想在 HoneyComb 下面的 API 上使用它,你应该尝试使用 NineOldAndroids 这是 HoneyComb 动画的一个端口来降低 API。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-20
        • 1970-01-01
        相关资源
        最近更新 更多