How to create layout-small-land folder?

2019-02-16 10:33发布

I want to create separate folders for my layouts, like this in my resource directory:

layout-land
layout-port

this is ok, but this:

layout-small-land
layout-small-port

or

layout-land-small
layout-port-small

Results in: 'Invalid resource directory name'

What gives?

4条回答
太酷不给撩
2楼-- · 2019-02-16 10:51

I haven't found anything else on the web that references this structure, but the following blog post shows an example where the author uses ldpi (and I'm sure mdpi and hdpi) instead of small, normal and large (as the android reference docs online would suggest). Have a look at the link below and maybe try that structure:

http://android.amberfog.com/?p=276

查看更多
一夜七次
3楼-- · 2019-02-16 11:00

It will give you a "invalid resource error" until the folder is empty. If you fill it with the .xml files (they have to match exactly in every layout-<qualifier> folders) it gives you no error.

EG:

layout-port

--> mainscreen.xml

layout-large-port

--> mainscreen.xml

it's ok

查看更多
叛逆
4楼-- · 2019-02-16 11:04

layout-small-land and layout-small-port are the correct answers, and they compile just fine for me. Perhaps there is something else amiss in your directory structure.

查看更多
小情绪 Triste *
5楼-- · 2019-02-16 11:06

You can specify the screen density instead of a size like Large or Small

Example:

layout-port-hdpi 
layout-port-ldpi 
layout-port-mdpi 
layout-port-nodpi 

layout-land-hdpi 
layout-land-ldpi 
layout-land-mdpi 
layout-land-nodpi 

More info in the following link:

https://developer.android.com/guide/topics/resources/resources-i18n.html#AlternateResources

For using Large, Medium, Small this is the way:

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
查看更多
登录 后发表回答