-6
 public class FirstTest extends Activity {
        public FirstTest() {
            // TODO Auto-generated constructor stub
        }

        RelativeLayout currentLayout;

        static int[] Deck = {
            R.drawable.img1,
            R.drawable.img2,
            R.drawable.img3,
            R.drawable.img4
        };

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            currentLayout = new RelativeLayout(this);

            for (int i = 0; i < Deck.length; i++) {         
                ImageButton img = new ImageButton(this);
                img.setPadding(0, 0, 0, 0);
                img.setImageResource(Deck[i]);
                img.setAdjustViewBounds(true);
                img.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View v) {
                        // TODO Auto-generated method stub

                        // BUT HOW MOVE THIS BUTTON????
                    }
                });

                currentLayout.addView(img);
            }
            setContentView(currentLayout);
        }
    }

Maybe it's trivial for others, but I just found width and height property modifiers. After trying a lot of examples I gave up.

How can I move something? Why can't I find x y properties?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
  • Take a look at http://stackoverflow.com/questions/4689918/move-image-from-left-to-right-in-android – Stuart Siegler Apr 11 '12 at 19:30
  • It almost good, but after the animation my ImageView return back to the origin position, and I don't understand why. I tried to override the onAnimationEnd method to set the image to the end position, but the image blink at once. Maybe it isn't the best way to make a simple card game. I don't understand how works android, this is my first days to change develop from flash to android. – Sandor Peterfy Apr 16 '12 at 13:52

1 Answers1

0

In your comment you mention how the image 'flashes' when it arrives at it's destination and then you no doubt set the image translation to the new position.

After much testing I found the best way to move an image (or any view) is to perform the steps in the following order:

On Click Event: 1. Find the coordinates of where you want the image to move to 2. Translate (set the position of) the image to where you want it to finish 3. Start an animation which starts from where the image was originally and ends back at it's current position (0,0).

Because the image has been moved to the end location and then instantly starts an animation you don't get any flashing at the beginning of the animation, then when the animation finishes it will end exactly where the image is already set to so you don't get any flashing at the end either.

It is a little strange but I believe it's just because of how Android triggers the Start/End Animation events.

I hope that makes sense.

Scott
  • 2,593
  • 1
  • 22
  • 23