78

I would like to create different layouts for tablets and handsets in Android. Where should I put the layout resources in order to make this differentiation?

hpique
  • 112,774
  • 126
  • 328
  • 461

6 Answers6

166

I know this is an old question, but for the sake of it... According documentation, you should create mutiple asset folders like this

res/layout/main_activity.xml           # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml   # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml   # For 10” tablets (720dp wide and bigger)
rds
  • 24,304
  • 16
  • 97
  • 124
urSus
  • 11,791
  • 12
  • 60
  • 86
45

If you are using Fragment concept in the code(means Multi-Pane layout) then its best to use wdp instead of swdp

res/layout-w600dp/main_activity.xml   # For 7” tablets (600dp wide and bigger)
res/layout-w720dp/main_activity.xml   # For 10” tablets (720dp wide and bigger)
res/layout-w600dp-land/main_activity.xml   # For 7” tablets in landscape (600dp wide and                  bigger)
res/layout-w720dp-land/main_activity.xml   # For 10” tablets in landscape (720dp wide and bigger)

Refer the table for understanding wdp

Table 2. New configuration qualifers for screen size (introduced in Android 3.2). In the following link http://developer.android.com/guide/practices/screens_support.html

Sakthimuthiah
  • 2,324
  • 6
  • 23
  • 40
23

With layouts, I believe you can only current differentiate by the following:

res/layout/my_layout.xml            // layout for normal screen size
res/layout-small/my_layout.xml      // layout for small screen size
res/layout-large/my_layout.xml      // layout for large screen size
res/layout-large-land/my_layout.xml // layout for large screen size in landscape mode

You can find more info on what you can add to the folder structure to differentiate between different settings here.

The biggest problem is that the Android SDK hasn't really incorporated tablets officially. Hopefully that will be resolved in the next version of Android. Otherwise, you just need to make sure you use scaling layouts that will work for any screen size.

Bryan Denny
  • 26,451
  • 32
  • 103
  • 124
  • I think the problem is not about the SDK. For example the phone has screen size 480x800 hdpi is enough for tablet layout. If your app works best with tablet layout then in that case, users don't need to have a tablet and still have its benefit. So no need to distinguish tablet/ phone. The link you pointed solves this perfectly. Thanks. –  May 31 '12 at 01:30
  • this is supported below Android 3.2 – Lalit Sharma Dec 03 '15 at 09:25
5

According documentation, you should create mutiple asset folders like this..full list......

res/layout/main_activity.xml  // For handsets (smaller than 600dp available width)
res/layout/main_activity.xml  // For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml  // For 7” tablets (600dp wide and bigger) 
res/layout-sw720dp/main_activity.xml  // For 10” tablets (720dp wide and bigger)
res/layout-sw600dp-land/main_activity.xml  // For 7” tablets in landscape (600dp wide and bigger)
res/layout-sw720dp-land/main_activity.xml  // For 10” tablets in landscape (720dp wide and bigger)
iUser
  • 1,035
  • 3
  • 19
  • 49
jaigish
  • 129
  • 2
  • 4
1

"Orientation for preview" dropdown in Android Studio as shown below can help generate quick landscape and tablet layout xmls. It also creates separate folders i.e. layout-land and layout-sw600dp for these layout variations and place the layout xmls within these folders. enter image description here

Nafeez Quraishi
  • 3,494
  • 2
  • 19
  • 29
0

This source also providing how to call any resources based on device configurations, like: language, screen width/height, layout direction, screen orientation...etc.

You've to be careful to make a default resource as the source mentioned, like calling high quality of icons for tablets.

Mohammad AlBanna
  • 2,003
  • 20
  • 22