android animation in different screen sizes

2019-09-02 22:29发布

问题:

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();

回答1:

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