0

So, when I say:

<Button
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_marginLeft="@dimen/login_left"
    android:layout_marginTop="@dimen/login_top"
    android:text=""
    android:id="@+id/button_login_fun" />

And I state in dimens.xml for screen size 1080x1920 and density xxhdpi:

<dimen name="login_left">325dp</dimen>
<dimen name="login_top">140dp</dimen>

I receive a different button position for Nexus 5 and Nexus 5X in Preview in Android Studio: Nexus 5

Nexus 5X

MickeyKSP
  • 43
  • 1
  • 10

1 Answers1

0

In Nexus 5 1dp = 3px, in Nexus 5X 1dp = 2.625px.
325dp and 140dp are not the same number of pixels on these two devices.

On the other side both devices have the screen of 1080x1920 pixels. This is the reason why you obtain a different rendering.

Massimo
  • 3,436
  • 4
  • 40
  • 68
  • So, what do you suggest? – MickeyKSP May 02 '16 at 12:41
  • It depends on what you have to do with that view. If you have to align it relatively to another view use a RelativeLayout. – Massimo May 02 '16 at 12:50
  • I need to place this button on same position on every possible screen...like in picture Nexus 5X – MickeyKSP May 02 '16 at 12:59
  • "same position" is an abstract concept when you have devices with different screen sizes and resoutions... what is that position? Is it the "FUN" string? If yes, your approach is wrong, because you should put that TextView and your Button on the same ViewGroup, placed one relatively to the other in the correct way (a FrameLayout, a RelativeLayout or what else); elsewhere you should calculate the "FUN" position at runtime and assign the padding to the Button programmatically. – Massimo May 02 '16 at 13:03
  • by "same position" I mean where the gray square is placed in picture Nexus 5X. Whole View is consisted with two images (one is background, not displayed at Nexus 5X), second is this Whole login window, and one button. There is no TextView. I set up layout_marginLeft and layout_marginTop to the values I define in dimens.xml. I make dimens.xml for every screen size. – MickeyKSP May 02 '16 at 13:17