如何在Android Studio中从A点到B点?

时间:2017-01-20 22:38:38

标签: java android android-studio

我试图让一个按钮从A点移动到B点,但我需要一个柔和的动作,而不是一个跳跃。像翻译一样。我该怎么办?

1 个答案:

答案 0 :(得分:0)

        make changes as per your need


        Animation animation = new TranslateAnimation(0, 500,0, 0);
        animation.setDuration(1000);
        animation.setFillAfter(true);
        yourButton.startAnimation(animation);
        yourButton.setVisibility(0);

    OR
    You can create Translate animation using ObjectAnimator. check link for more information

    ObjectAnimator transAnimation= ObjectAnimator.ofFloat(YourButton, propertyName, fromX, toX);
    transAnimation.setDuration(3000);//set duration
    transAnimation.start();//start animation

Example
ObjectAnimator anim = ObjectAnimator.ofFloat(yourButton, "translationX", 0,200); and then 
 anim.setDuration(3000);
 anim.start();