Search code examples
androidandroid-layoutandroid-tablayoutandroid-tablet-layout

Android mobile in landscape is picking up tablet layout


I have a tab-layout in my Android app where I have two different designs for mobile vs tablet. I have followed this page to create two different layout files:

  1. res/layout/myLayout.xml (this is for mobile app)
  2. res/layout-w600dp/myLayout.xml (this is for tablets 7")

Now, when I am using my mobile in landscape, and I open the app, its picking up the layout defined for the tablet(layout-w600dp) instead of the one for mobile(layout). This is causing issues showing the layout defined for tablet showing up in the mobile app.

I have tried by defining the tablet's layout in layout-sw600dp but its not coming up expected in the tablet.

Thanks in advance. Appreciate your time.


Solution

  • The correct solution in this case was using layout-sw600dp instead of layout-w600dp.

    The layout from layout-w600dp is picked everytime the screenwidth is more than 600dp (including mobile in landscape mode)

    Layout from layout-sw600dp is only used when the shortest width is more than 600dp, orientation dosent matter, hence works only for tablets.