Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move an image from left to right in android

I'd like to translate an image from left to right on emulator using android animation. I'm new to android animation. How could I do that?

Thanks.

like image 253
sanjay Avatar asked Jan 14 '11 10:01

sanjay


People also ask

How to move image from left to right in android?

setText("Animation"); moveLefttoRight = new TranslateAnimation(0, 200, 0, 0); moveLefttoRight. setDuration(1000); moveLefttoRight. setFillAfter(true); button = new Button(this); button. setLayoutParams(new LayoutParams(LayoutParams.


2 Answers

    ll = new LinearLayout(this);     ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));     ll.setOrientation(LinearLayout.VERTICAL);      tv = new TextView(this);     tv.setText("Animation");      moveLefttoRight = new TranslateAnimation(0, 200, 0, 0);     moveLefttoRight.setDuration(1000);     moveLefttoRight.setFillAfter(true);      button = new Button(this);     button.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));     button.setText("PressMe");     button.setOnClickListener(new OnClickListener() {          public void onClick(View v) {             tv.startAnimation(moveLefttoRight);         }      });      ll.addView(tv);     ll.addView(button);     setContentView(ll); 

is one way of doing it.

like image 91
techiServices Avatar answered Sep 19 '22 23:09

techiServices


Move an image from left to right and right to left by using Android TranslateAnimation

enter image description here

ImageView img_animation = (ImageView) findViewById(R.id.img_animation);      TranslateAnimation animation = new TranslateAnimation(0.0f, 400.0f,             0.0f, 0.0f);          //  new TranslateAnimation(xFrom,xTo, yFrom,yTo)     animation.setDuration(5000);  // animation duration      animation.setRepeatCount(5);  // animation repeat count     animation.setRepeatMode(2);   // repeat animation (left to right, right to left )     //animation.setFillAfter(true);            img_animation.startAnimation(animation);  // start animation  

you can find more details from here

like image 30
Chathura Wijesinghe Avatar answered Sep 22 '22 23:09

Chathura Wijesinghe