Reputation: 1340
I have a ImageView called myimage.
I'm doing it TranslateAnimation from just outside the screen on one side to just outside the screen on the other side.
Animation animation = new TranslateAnimation(0, 0, -1500, 1500);
animation.setDuration(1000);
animation.setFillAfter(false);
myimage.startAnimation(animation);
Is there any way that lets me move it from just outside the screen on one side to just outside the screen on the other side regardless of any screen size ?
Upvotes: 3
Views: 1609
Reputation: 1340
I have got it now.
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
final float screen_width_half = metrics.widthPixels/2;
final float distance = screen_width_half + 50;
//determine half screen width and add 50 to it to take it just a little outside the screen
Animation animation =
new TranslateAnimation(0, 0, -distance, distance);
animation.setDuration(1000);
animation.setFillAfter(false);
myimage.startAnimation(animation);
Upvotes: 5