android animation in different screen sizes

2019-09-02 22:24发布

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条回答
够拽才男人
2楼-- · 2019-09-02 23:01

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

查看更多
登录 后发表回答