2

I have been trying to understand why these two devices even though having same screen size and pixel density behave differently.

Please Note: The Font size and Display size are set to "Default" on both the devices.

EDIT 1: I have created the following folders in the layout folder. layout-hdpi layout-xhdpi layout-xxhdpi layout-xxxhdpi

Each folder has the activity's layout with the dimension and image size fixed. My point is, if the two mobiles are using xxhdpi layouts or the Google Pixel is using xxxhdpi and Google Pixel 2 is using xxhdpi?

App Preview on Google Pixel 2 Emulator

App Preview on Google Pixel Emulator

  • You have to make different dimension(dimens.xml) for different layout . – Praveen Rawat Apr 03 '18 at 12:46
  • 1
    I think there is a slight difference in Screen-to-body ratio 67.92 % for Pixel 2 and 68.88 % for Pixel. Also when you created emulator did you noticed Pixel 2 is 420dpi and Pixel is xxhdpi, so there is a difference in dpi. – Sunil Sunny Apr 03 '18 at 12:49
  • You should not spend time with this. I'm pretty sure that @sunilsunnywas right in his comment about what is the cause of problem. Having different displays on two different devices, it's expected to have different layouts in the end. – Iulian Popescu Apr 03 '18 at 13:23

2 Answers2

0

I think it depends on DPI of your phone. Two phones may have different dpi. You can change dpi if phone is rooted. I dont know if stock supports.

  • So can you suggest on how should I declare the layout files so that it looks same on both the devices? I am confused! – user1496259 Apr 03 '18 at 13:05
0

Please Note: The Font size and Display size are set to "Default" on both the devices.

No , You have to using dimens.xml for different devices of android for Example see Below structure :

res/values/dimens.xml

res/values-small/dimens.xml

res/values-normal/dimens.xml

res/values-large/dimens.xml

res/values-xlarge/dimens.xml

dimens.xml file contains

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <dimen name="text_size">18sp</dimen>
</resources>

In Textview add this

android:textSize="@dimen/text_size"
Praveen Rawat
  • 314
  • 1
  • 3
  • 14