0

I've downloaded the sample project on this blog android button animation. I tried to modify the code and change the position of the button, but when I change position also with animation, it's like the screen is divided in section and every section have one animation. How can I apply one of any animation at one single button that I can move in every part of the screen?

1 Answer 1

1

It seems that you are not very familiar with Android, because the example that you have posted is very self-explicative.

As you can see the main layout is composed by a LinearLayout where are inserted four different button. The item inside a LinearLayout are displayed one after the other, so the only position specified in that layout is the option

   android:layout_margin="10dp"

If you need to specify different position (absolute position on the screen) I suggest you to use a RelativeLayout and set marginTop and MarginLeft option for every button inside your XML.

To apply an animation to a button you have simply to reply the code posted in your example:

   btnTranslate.setOnClickListener(new Button.OnClickListener(){

   @Override
   public void onClick(View arg0) {
          arg0.startAnimation(animTranslate);
   }});

After the definition of the button and the animation;)

Sign up to request clarification or add additional context in comments.

7 Comments

Can you explain me why if I exchange two button (e.g. translate and alpha) the button change animation?
You have to be more specific, where did you exchange your button? Only inside your XML, inside your code, or maybe in both places?
If I change the position by the graphic interface with Eclipse!
If your code is the same of the example every animation is linked by onClickListener to the homonymous animation. If you changed your code is better if you insert it in your question.
I don't have changed nothing!
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.