1

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.

user3543477
  • 615
  • 3
  • 13
  • 26
  • Have you tried orientation qualifiers: https://developer.android.com/training/multiscreen/screensizes#TaskUseOriQuali ? – Morrison Chang Apr 14 '21 at 05:09
  • @MorrisonChang Having a duplicate file on layout-land works and I have tried using aliases to avoid duplicate files definitions. But its throwing me the error "android.content.res.Resources$NotFoundException: Resource ID #0x7f0d0082 type #0x1 is not valid" – user3543477 Apr 15 '21 at 17:51
  • You should show code/layout. I would also rebuild app from scratch just in case. – Morrison Chang Apr 15 '21 at 17:55

2 Answers2

2

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.

user3543477
  • 615
  • 3
  • 13
  • 26
1

Make landscape version of your layout res/layout-land/myLayout.xml and copy content of your original layout into that new file. It will get inflated on landscape orientation.

End User
  • 792
  • 6
  • 14
  • It works but wouldn't it be a duplicate of resource file? I have tried using https://developer.android.com/training/multiscreen/screensizes.html#TaskUseAliasFilters but its throwing "android.content.res.Resources$NotFoundException: Resource ID #0x7f0d0082 type #0x1 is not valid" error. – user3543477 Apr 15 '21 at 17:49
  • What you may be trying is two pan layout that is different from what you have asked.if you want to try two pan layouts follow this. https://developer.android.com/guide/topics/ui/layout/twopane – End User Apr 15 '21 at 18:01