如何使用单个xml布局文件在android中支持多种屏幕尺寸 [英] How can i support multiple screen sizes in android with single xml layout file

查看:78
本文介绍了如何使用单个xml布局文件在android中支持多种屏幕尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在多种屏幕尺寸上支持我的android屏幕,但是我可以通过维护多个xml布局文件来做到这一点

I want to support my android screen in multiple screen sizes but i can do it with maintaining multiple xml layout file's

但是根据要求,我应该使用单个XML布局来完成,以优化应用程序的使用.

but according to requirement it i supposed to be done with the single XML layout in order to optimize the app usage.

所以请你能帮我吗我经历了多个教程的多个链接,但无法获得堆栈溢出的最后一个选择

so please can you help me i have gone through multiple tutorials multiple links but not able to get last option with stack overflow

推荐答案

可绘制:

对于图像,您必须根据屏幕分辨率管理不同的可绘制文件夹:

For images, you have to manage different drawable folders as per screen resolution:

drawable-ldpi        //240x320
drawable-mdpi        //320x480
drawable-hdpi        //480x800
drawable-xhdpi       //720x1280
drawable-xxhdpi      //1080X1920
drawable-xxxhdpi     //1440X2560
drawable-tvdpi       // nexus 7 etc 
drawable-xlarge-xhdpi //tablet like nexus 10  

角钱:对于Dimens,如果根据UI使用不同的静态Dimes,则必须根据它们的value ...文件夹定义它们.

dimes: For dimens, If you are using different static dimes as per your UI then you have to define them respected to their values... folders.

用于不同智能手机分辨率的Values文件夹:

Values folder for different smart phones resolutions:

values-ldpi\dimens.xml
values-mdpi\dimens.xml
values-hdpi\dimens.xml
values-xhdpi\dimens.xml
values-xxhdpi\dimens.xml
values-xxxhdpi\dimens.xml

注意:如果使用的是sp/sip/dp/dip,则将根据设备的密度调整这些值.例如,假设您已在mdpi(320X480)分辨率设备中为TextView设置了10sp.然后,将为其他分辨率自动调整此相同的值.

Note: If you are using sp/sip/dp/dip then these values will be adjusted based on the density of device. e.g Suppose you had set 10sp for TextView in mdpi(320X480) resolution device. Then this same value will be auto adjusted for other resolutions.

mdpi(10sp==10px)
hdpi(15px)
xhdpi(20px)
xxhdpi(30px)
xxxhdpi(40px)

这些是一些通用值文件夹,用于管理与屏幕分辨率有关的变暗.

These are the some general usage values folder which are used to manage dimens related to their screen resolutions.

用于不同屏幕的不同值文件夹:

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-xxxhdpi                 1440X2560 xxxhdpi

values-xxhdpi                  1080X1920 xxhdpi

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

要深入了解,请使用支持屏幕分辨率

这篇关于如何使用单个xml布局文件在android中支持多种屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆