Reputation: 1340
I wrote this code for an android Translate Animation on x axis -
ImageView myimage = (ImageView)findViewById(R.id.myimage);
Animation animation = new TranslateAnimation(0, 80, 0, 0);
animation.setDuration(100);
animation.setFillAfter(true);
myimage.startAnimation(animation);
This image moves the same 80 units on all screen sizes.
Is there any way so that it moves a distance equal to 80% of the screen width ?
Upvotes: 1
Views: 1442
Reputation: 44118
You can just calculate it yourself:
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
float calculatedWidth = metrics.widthPixels * 0.8f;
Animation animation = new TranslateAnimation(0, calculatedWidth, 0, 0);
animation.setDuration(100);
animation.setFillAfter(true);
Upvotes: 4