反向位置的TranslateAnimation?

6
我正在开发一款应用程序,其中使用了TranslateAnimation,但我希望将TranslateAnimation反转到起始位置。
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        setContentView(R.layout.imageviewactivity);

        TranslateAnimation toptranslateanimation = new TranslateAnimation(0, 0, tempBar,
                    scanner_image.getHeight() - 50);
        toptranslateanimation.setDuration(4000);
            toptranslateanimation.setAnimationListener(this);
                scanning_bar.setAnimation(toptranslateanimation);
}

它对我起作用了,检查这个链接https://dev59.com/wGw05IYBdhLWcg3wXQsh] - Mushtaq Rahim
2个回答

9

尝试使用这段代码

toptranslateanimation.setRepeatCount(1);
toptranslateanimation.setRepeatMode(Animation.REVERSE);

1

使用 Interpolator 实现这个,像这样:

package com.example.android;

import android.view.animation.Interpolator;

public class ReverseInterpolator implements Interpolator {
    @Override
    public float getInterpolation(float paramFloat) {
        return Math.abs(paramFloat -1f);
    }
}

然后,在您的动画中,您可以设置新的插值器:
toptranslateanimation.setInterpolator(new ReverseInterpolator());

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接