Reputation: 5547
I am using the following translate animation to move an image vertically down onto the screen in my android app. However, currently it goes to a fixed position of 150. I would like this value to be dependent on the screen size. For example, I want the image to stop at 20% of the users screen length, starting from the top of the screen. How would I adjust the y delta value to accomodate this?
mScanner = (ImageView)findViewById(R.id.logo_img);
mAnimation = new TranslateAnimation(0, 0, -300, 150);
mAnimation.setDuration(2500);
mAnimation.setFillAfter(true);
//mAnimation.setRepeatCount(-1);
// mAnimation.setRepeatMode(Animation.RESTART);
mScanner.setAnimation(mAnimation);
mScanner.setVisibility(View.VISIBLE);
Upvotes: 0
Views: 1712
Reputation: 163
To get the device screen lenght (height):
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
And now for 20%, set the animation like this:
mAnimation = new TranslateAnimation(0, 0, -300, height*2/10);
Upvotes: 2
Reputation: 195
you could get the user's screen size programatically using Get Size
This Question deals with just that : Get screen dimensions in pixels
You would then replace 150 by whatever variable you define the size to be.
Upvotes: 0