How to prepare layout,drawable folders for 7“,10” android tablets for both landscape and portrait?

房东的猫 提交于 2019-11-28 19:13:16

问题


I have prepared my drawables for 7" tablets as (Nexus 7)

 drawable-large-hdpi-port
 layout-large-hdpi-port

I am getting errors while doing this. I didnt understand where I am doing wrong.

I want to prepare layouts for both landscape and portrait for both 7", 10" tablets


回答1:


The recommended way is to use layout-swxxdp qualifier. If you need to differentiate landscape/portrait

res/layout-sw600dp/   # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/   # For 10” tablets (720dp wide and bigger)
res/layout-sw600dp-port/   # For 7” tablets in portrait (600dp wide or bigger)
res/layout-sw720dp-port/  # For 10” tablets in portrait (720dp wide or bigger)



回答2:


try below :-

values-sw720dp  10.1” tablet 1280x800 mdpi

values-sw600dp  7.0”     tablet 1024x600 mdpi

values-sw480dp      5.4” 480x854 mdpi 
values-sw480dp      5.1” 480x800 mdpi 

values-xhdpi          4.7”   1280x720 xhdpi 
values-xhdpi          4.65” 720x1280 xhdpi 

values-hdpi            4.0” 480x800 hdpi
values-hdpi            3.7” 480x854 hdpi

values-mdpi           3.2” 320x480 mdpi

values-ldpi             3.4” 240x432 ldpi
values-ldpi             3.3” 240x400 ldpi
values-ldpi             2.7” 240x320 ldpi

also see below :-




回答3:


You are naming the folders in the wrong way. In Android, there is a rule or order in which you name your resource folders. You should provide your qualifier names in that order.

Check this documentation table on providing resources. Your should name your folders in the order provided in the table.(Its better if you read the whole page, because it'll give you a better understanding in providing resources)

Here you should name the folders as

layout-large-port-hdpi
drawable-large-port-hdpi

For preparing the resource folders for tablets, you can use either the screen size attribute or shortest width attribute.

For e.g

If you use screen size attribute, you can name folders like

layout-large-... (for 7" devices)
layout-xlarge-... (for 10" devices)

I you use shortest width attribute, you can use

layout-sw600dp-... (for 7" devices)
layout-sw720dp-... (for 10" devices)

Remember shortest width attribute works only on devices from 3.2 (API 13).




回答4:


Use this:

Wrong: drawable-hdpi-port/
Correct: drawable-port-hdpi/

You can see this link



来源:https://stackoverflow.com/questions/17647507/how-to-prepare-layout-drawable-folders-for-7-10-android-tablets-for-both-lands

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!