0

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);
Alk
  • 5,215
  • 8
  • 47
  • 116

2 Answers2

2

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);
theMatus
  • 153
  • 1
  • 9
0

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.

Community
  • 1
  • 1
Viralwarrior012
  • 185
  • 1
  • 14