制作弹跳动画 [英] Make bounce animation

查看:87
本文介绍了制作弹跳动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做图层的弹跳动画.

I would like to do bounce animation of layer.

我已经完成了该层从右到中心的操作,现在我想将其移回一点然后再回到中心.这样会产生反弹效果.

I have done that layer comes from right to center, now I would like to move it a little back and then back to center. That would create bounce effect.

我当时想我可以通过这样的翻译来做到这一点:

I was thinking that I can do it with a translate like this:

<translate
    android:duration="900"
    android:fromXDelta="100%p"
    android:toXDelta="0%p" />

<translate
    android:duration="900"
    android:fromXDelta="0%p"
    android:toXDelta="100%p" />

<translate
    android:duration="900"
    android:fromXDelta="70%p"
    android:toXDelta="0%p" />

好吧,这段代码不起作用,我唯一能实现的就是图层从左到中心,然后动画停止.

Well this code does not working, only thing I can achieve is that Layer comes from left to center, and then animation stops.

我不能使用此代码:因为它无法实现我想要的

I cannot use this code: because it does not achieve what I want

setInterpolator(AnimationUtils.loadInterpolator(this,
                        android.R.anim.bounce_interpolator));

任何帮助将不胜感激.

推荐答案

您可以使用 BounceInterpolator 具有此效果. 文档包含了很好的使用说明在XML中.拥有这样的动画xml:

You can use the BounceInterpolator to have this effect. The docs contain a very good description how to use it in XML. Just have a animation xml like this:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"

    android:interpolator="@android:anim/bounce_interpolator">

    <!-- Use your working translate animation here-->
    <translate
        android:duration="900"
        android:fromXDelta="100%p"
        android:toXDelta="0%p" />
</set>

这篇关于制作弹跳动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆