Zoe - Save the data dump
Zoe - Save the data dump

Reputation: 28228

Is there a need to keep both "layout" and "layout-sw400dp"?

I am currently developing an app and I am using sw<N>dp in order to create support for multiple screens.

I added the sw400dp folder, which basicly takes all the smaller phones according to Android Studio's XML renderer.
Which means it overrides the layout folder. So now it is just sitting there and taking up space.
Have I gone about this wrong?
Should sw400dp be the layout folder and build bigger layouts in their own folders?
Or can I delete the layout folder without issues?

Upvotes: 3

Views: 726

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006644

I added the sw400dp folder, which basicly takes all the smaller phones according to Android Studio's XML renderer. Which means it overrides the layout folder. So

Only for devices whose smallest width is 400dp or greater. 400dp is 2.5in or 6.35cm. I would estimate that there are a couple hundred million Android devices in use whose smallest width is smaller than that.

Have I gone about this wrong? Should sw400dp be the layout folder and build bigger layouts in their own folders?

Probably. You would only have a res/layout-sw400dp/ directory if you have layout resources that need to be different for devices whose smallest width is 400dp or greater. Most of your layout resources will not need to be different for that specific size, which means the version of the layout resource in res/layout/ would be enough.

Or can I delete the layout folder without issues?

No, because then your app will crash on devices whose smallest width is less than 400dp.

The rules are simple:

  • Put one of every layout resource in res/layout/

  • Put modified copies of layout resources in other directories if they need to be different for the criteria specified in the directory name

So, unless you clearly need different layouts for 400dp-and-wider devices, when compared to smaller-than-400dp devices, you would not need res/layout-sw400dp/.

Upvotes: 5

Related Questions