0

I am animating a layout which contains a button and a spinner using objectAnimator.In my mobile the layout moves to top.But when I tried to run the app in another mobile with larger screens size,it moved to half the screen.How can I get the x and y axis of screen .The code is below. MainActivity.java:

ObjectAnimator translate=ObjectAnimator.ofFloat(relativeLayout1,"translationY",0,-174);
                   translate.setDuration(1000);
                   translate.start();
jobin
  • 1,489
  • 5
  • 27
  • 52
  • see this link http://stackoverflow.com/questions/1016896/get-screen-dimensions-in-pixels – N J Feb 23 '16 at 05:44
  • isn't the top of the screen x,y = 0,0 ? – Bhargav Feb 23 '16 at 05:45
  • I set the value to -174.It works perfectly in my phone.I want to get the top most y axis position of any screen so that I can do -top+20 and set it to animate to that position.@NJNIiesh The code in the link you shared gives the pixels(1080X1920) – jobin Feb 23 '16 at 05:55

1 Answers1

1

First, access to the screen dpi,then target yoffset = target dpi / your dpi * your yoffset

SevenHuang
  • 31
  • 2