2

I want my app to look the same on all screen sizes. I read some articles, that says to have different layout folders like layout-sw320dp, layout-600dp.. etc. I did that. But the problem is, Nexus 5 and Nexus 7 uses same layout folder(layout-600dp).

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • 1
    You can use the `swXXXdp` layouts for screen width instead of purely density... However, res/layout fits maybe 80% of all cases when using proper scaling and relative layouts – OneCricketeer Jul 26 '17 at 02:27
  • Usually you'd use e.g. layout-sw600dp to make your layout look **different** on different screens. Like a two-pane layout for tablets with a single-pane for phones. If you just want everything to scale up, you can use LinearLayout with layout_weight or use ConstraintLayout with % Guidelines – Ben P. Jul 26 '17 at 02:29
  • I'm making a game in Android studio. I use svg files for ImageViews and Buttons. Every layout file is in relative layout. It is not a regular app. – Nidhin Velayudhan Jul 26 '17 at 02:33
  • 1
    So if you want to use the same layout for all screen sizes, don't create extra versions of your layout in `layout-sw600dp`. Just use the default `layout` folder, and use something like `ConstraintLayout` to make all of your views percentage-based instead of fixed-size. If you have an example layout I can help. – Ben P. Jul 26 '17 at 04:43
  • @BenP. BEST ADVICE!!!!!!!!! For future readers, this link describes how to do that: https://developer.android.com/reference/androidx/constraintlayout/widget/ConstraintLayout?hl=id#percent-dimension – Squareoot Aug 09 '22 at 20:35

3 Answers3

4

A set of six generalized densities:

ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi

Layout Explaination

(Or) You used this type of layout folder

res/layout/my_layout.xml              // layout for normal screen size ("default")
res/layout-large/my_layout.xml        // layout for large screen size
res/layout-xlarge/my_layout.xml       // layout for extra-large screen size
res/layout-xlarge-land/my_layout.xml  // layout for extra-large in 
Jai
  • 486
  • 1
  • 8
  • 21
0

Yes ,It is right that for different devices you have to make different layouts But here is alternate solution for it that is sdp library.By using this library you have to make only one layout and set all dimension in sdp, that works with alldifferent devices.This library is awesome to solve your problem.

PRIYA PARASHAR
  • 777
  • 4
  • 15
0
You should create all the layout folders
 layout-sw300dp, 
 layout-sw330dp, 
 layout-sw480dp, 
 layout-sw600dp and 
 layout-sw720dp also create values folders to set dimensions
 values-sw300dp,
 values-sw330dp, 
 values-sw480dp, 
 values-sw600dp, and
 values-sw720dp

   a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc). 
   480dp: a tweener tablet like the Streak (480x800 mdpi). 600dp: a 7” tablet 
  (600x1024 mdpi). 720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).
MinnuKaAnae
  • 1,646
  • 3
  • 23
  • 35