Muhammad Maqsoodur Rehman
Muhammad Maqsoodur Rehman

Reputation: 34257

Android: How to change the position of ImageView dynamically?

I want my arrows to continuously move left and right with a delay of certain milliseconds dynamically. Any clue?

Here's my code:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;

public class PlayWithGraphics extends Activity {
    /** Called when the activity is first created. */

 public final int delay = 2500;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final ImageView iv = (ImageView)findViewById(R.id.iv);
        iv.setBackgroundResource(R.drawable.back_two);

        new Handler().postDelayed(new Runnable(){
            public void run(){ 


          //iv.setPadding(30, 0, 10, 0);   
            }
        }, delay); 




  }
    }

Upvotes: 0

Views: 4306

Answers (1)

Sephy
Sephy

Reputation: 50392

You could either use a translate animation and update the movement in the onRepeatListener or put your image in a RelativeLayout and change its margin at regular intervals.

Upvotes: 2

Related Questions