开发者

How to do Translate Animation Button in android?

I want to do a translate (change the position) one button when click another button. I hope to use translate animation to do that. but I dont have good idea to do t开发者_开发问答hat. pls help me with a code.

thanks


you can do this as follows:

Animation animation = new TranslateAnimation(0, 500,0, 0);
animation.setDuration(1000);
yourbutton.startAnimation(animation);

You can take more than one translateanimation object and set their duration so that they will start one after another.

You can also add animationlistener to perform different functions.


Take a look at TranslateAnimation class. It's easy to use. Here is an outline:

  • Create a TranslateAnimation object.
  • Set the required attributes like setFillAfter, setAnimationListener, setDuration, setInterpolater, etc
  • Call mButton.startAnimation(translate animation obj) to start the animation.


you can use the layout params to change the position of the button when clicked other button

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
     LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

layoutParams.setMargins(30, 20, 30, 0);

yourbutton.setLayoutParams(layoutParams);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜