tags:

views:

162

answers:

1

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); 




  }
    }
+1  A: 

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.

Sephy
Now you gave 2 suggestions:1. use a translate animation and update the movement in the onRepeatListener OR2. put your image in a RelativeLayout and change its margin at regular intervalsFor number 1: do you have a code example that you can post here or refer a tutorial on the web? For number 2: id don't have the required method available to me at runtime. I used setPadding but it didn't work. setMarginLeft and setMarginRight are only available at design time in XML layout.
Maxood
Well, about method 2, actually no, these methods are clustered into one that you will find in `LayoutParams` from `RelativeLayout`. You just have to use a background thread which does the counting and every now and then, you change the margins. I'll have a go a that this afternoon and try to come back with some code/screenshot. Though I think the translate animation is the easiest way to do that... You refer to the translate animation in ApiDemo. or simply create your own instance. Again I'll have a look and give you more details later.
Sephy