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(){开发者_StackOverflow社区
public void run(){
//iv.setPadding(30, 0, 10, 0);
}
}, delay);
}
}
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.
精彩评论