1

I am developing the app for mobile and tablet devices. In following screenshot I have applied button size as android:layout_width="200dp" android:layout_height="80dp". When I run my application in a tablet(mdpi) and in other two mobile devices (hdpi) and (xhdpi) the button size varies as all three devices has different densities.

Refer to the following image which has tablet(mdpi), nexus mobile(hdpi) and galaxy nexus mobile(xhdpi) emulator repectively: enter image description here

I have also checked with the Gmail app in all 3 devices: enter image description here

As the tablet has a bigger size but the lowest density(mdpi) the UI in tablet looks smaller compared to other devices which have the comparatively small size and high density.

If I want the button to look bigger in the tablet I need to change the height and width by adding different dimensions in values-sw360dp,values-sw480dp, values-sw600dp, etc.

My question is, should our UI look bigger as per screen size or let it vary as per density? Which is the best practice to follow?

Kavita Patil
  • 1,784
  • 1
  • 17
  • 30

2 Answers2

0

There's no specific guidelines for this and I believe there's no best practice either.

Personally, I allow the UI to look bigger as per screen size, due to this being the same behavior for the majority of other apps on the phone. I only adjust the dp and sp values for these larger sizes if I notice text being cut off.

However, since there's no best practices, this does fall down to personal choice. I prefer keeping UI similar to other apps on the device, which also get enlarged.

But I do know other developers who prefer to keep the UI consistent. If you choose to do the same, you can consider using these two libraries:

Jackey
  • 3,184
  • 1
  • 11
  • 12
0

I think that the best practice to use is to have 1 layout for all screen sizes using ConstraintLayout.
When you use fixed size on your views like android:layout_width="200dp" android:layout_height="80dp" your layout it not responsive to all screen sizes.

If you want your layout to be exactly the same on all of the different physical screens use constaintLayout.

From the documentation:

ConstraintLayout allows you to create large and complex layouts with a flat view hierarchy (no nested view groups). It's similar to RelativeLayout in that all views are laid out according to relationships between sibling views and the parent layout, but it's more flexible than RelativeLayout and easier to use with Android Studio's Layout Editor.

Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53
  • if I use `ConstrainLayout` and if I apply size percentage wise, let say `buttonTop` at 10% and `buttonBottom` at 20%. Then that will make a huge difference with the layout of 4" mobile and 6" tablet. The button height will look way bigger in the tablet. Thank you – Kavita Patil Mar 16 '19 at 21:47
  • 1
    It will only look bigger because your screen is bigger, but it will stay relative to your screen and keep its size ratio. But if you want to change the size of your views according to your screen size that's acceptable and it is also one way to look at the subject. – Tamir Abutbul Mar 16 '19 at 21:53