Animate Image Move Left To Right in android

by mariganesh 2014-03-01 15:01:12

Android Animate Image Move Left To Right


Just Copy the code and use it .Here animate the image move left to right and right to left using by translate animation.



import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.os.Bundle;

import android.view.View.OnClickListener;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.button1);

btn.setOnClickListener(btn_func);


}
private OnClickListener btn_func = new OnClickListener() {
public void onClick(View v) {

movee();

}
};
public void movee()
{
ImageView img_animation = (ImageView) findViewById(R.id.img_animation);


TranslateAnimation moveLefttoRight = new TranslateAnimation(0, 100f,0, 0f);
moveLefttoRight.setRepeatCount(0);
moveLefttoRight.setRepeatMode(1);
moveLefttoRight.setDuration(1000);
img_animation.startAnimation(moveLefttoRight);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}



1269
like
0
dislike
0
mail
flag

You must LOGIN to add comments