应用程序框架可支持多个屏幕 [英] Application Skeleton to support multiple screens
问题描述
我们知道Android配备了各种不同的设备 功能,分辨率和屏幕尺寸,以便在开发支持以下功能的应用程序时 多个屏幕(大小)存在尺寸和布局上的障碍.
As we know Android coming with various device which having different Features, Resolution, and Screen-size so while developing an Application which support multiple (small and big) screen there is an obstacle of size and layout.
这导致屏幕尺寸,分辨率和DPI 的不同组合,并且在为Android设备进行设计和开发时带来了很大的挑战.尽管其他一些制造商(非Android)具有不同的分辨率和DPI,但它们共享相同的屏幕尺寸,并且分辨率遵循相同的宽高比.因此,可以创建适合非Android设备的图像.
This leads to different combinations of screen sizes, resolutions, and DPIs and creates quite a challenge when designing and developing for Android devices. While some other Manufacturer (non Android) have different resolutions and DPI, they share the same screen size and the resolutions follow the same aspect ratio. Therefore, an image can be created to fit the non Android devices.
我的问题是,应该遵循一种适当的流程或体系结构来满足要求吗?
My question is that is there a proper flow or architecture that one should follow to meet the requirement?
请记住,我们确实有不同尺寸和分辨率的平板电脑.
我知道 Android开发人员 包含此信息,但我的观点来自于实现.
I'm aware that Android Developer contains this information but my view is from implementation.
据我所知,即使是程序员,对于设计Android图形也必须了解设计概念.
From my knowledge what I understood is that for designing Android graphics even Programmer must know the designing concept.
推荐答案
最后创建了一个结构,用于处理多屏幕的布局和图标.
Finally created a structure which handle layouts and icon for multiple screen.
Android根据两个参数将设备显示归为一类:
Android generalises device displays into categories based on two parameters:
- 屏幕尺寸,显示器的物理尺寸(对角线测量)
- 屏幕密度,即显示器的物理像素密度(以每英寸像素数或ppi为单位).
确定屏幕尺寸&快速安装密度,请安装"我的尺寸是多少适用于Android的应用.
To determine screen size & density quickly, please install "What's my Size" app for Android.
屏幕尺寸
Android定义了四种通用的屏幕尺寸:
Android defines four generalised screen sizes:
Qualifier Size
small ~3 inches (approx)
normal ~4 inches (approx)
large Exceeds 4 inches
xlarge Exceeds 7 inches
- 大多数电话被归类为小型或普通(对角线约3到4英寸).但是现在,有很多大屏幕手机,例如Galaxy S4,HTC One,Xperia Z
- 像Samsung Galaxy Tab这样的小型平板电脑被归类为大型(大于4英寸)
- 特大号适用于大型设备,例如大型平板电脑
Android定义了四种通用的屏幕密度:
Android defines four generalised screen densities:
Qualifier Description Nominal value
ldpi low density 120 ppi
mdpi medium density 160 ppi
hdpi high density 240 ppi
xhdpi extra high density 320 ppi
通常:
- 屏幕尺寸对您的应用布局影响最大
- 屏幕密度对您的图像和图形资源影响最大
在此处设备屏幕的百分比差异
It is listed here the percentage difference of device screen
- Ldpi- 75%
- Mdpi- 100%(根据Android开发者网站为基准)
- Hdpi- 150%
- XHdpi- 200%
但是,正如我们现在所知道的,大多数设备都随附 480X800 ,因此我认为这是基于设备的设备,因此我们的新计算将是这样
But as we know now most of device coming with 480X800 so I'm consider this as based device, so our new calculation will like this
- Ldpi- 50%
- Mdpi- 66.67%
- Hdpi- 100%
- XHdpi- 133.33%
,这意味着将仅为 480X800 创建第一个图标和设计,然后为其余图标(即Ldpi,Mdpi,Xhdpi)创建图标.
which means that first icon and design will be created for 480X800 only and then for rest ones(i.e. Ldpi, Mdpi, Xhdpi).
有些图像在所有布局中都是通用的,必须在颜色和形状上统一(没有复杂的形状,没有曲线),因此对于这种图像,我们正在创建9patch
并将其放置在"drawable(无后缀)"中)"文件夹.要创建9Patch图像,您可以使用 DrawNinePatch 或 BetterNinePatch
There are images which are common for all layout and must uniform in color and shape(no complex shape, no curve) so for this kind of image we are creating 9patch
which to be put in "drawable(no-suffix)" folder. To create 9Patch image you can either use DrawNinePatch or BetterNinePatch
现在只需根据Android标准重命名图像,并使用hdpi
完成您的应用程序,然后打开drawable-hdpi
文件夹并打开 Adode Photoshop (推荐)
创建多个尺寸的 动作 (只需根据百分比)).一旦针对所有尺寸创建了操作,则只需 批处理自动化 并指定源(drawable-hdpi)和目标(drawable-ldpi,drawable-mdpi,drawable-xdpi).
Now just rename your images based on Android's standards and complete your application with hdpi
and then just take drawable-hdpi
folder and Open Adode Photoshop(recommended)
create Action of multiple size(just change the size according to percentage ratio) once Action created for all size then just do Batch Automate and give source(drawable-hdpi) and destination(drawable-ldpi, drawable-mdpi, drawable-xdpi).
之所以我之所以坚持使用Photoshop是因为它会通过Actions和其他加号自动调整图像的大小,而无需重命名该文件(它会分配与原始名称相同的名称).
The reason I insist you to use Photoshop because it will resize automatically your image with Actions and one more plus point is that you need not to rename the file(it will assign same name as original one).
完成所有图像的创建后,刷新项目并进行测试.
once you completed with creation of all images, refresh your project and test it.
有时可能会在小屏幕(ldpi)上剪切支持屏幕(xhdpi,hdpi,mdpi)的布局,因此要处理此问题,只需为其创建单独的Layout文件夹(layout-small)并添加ScrollView
(大部分).就是这样.
Sometimes there may be possibility that the layout which support screen(xhdpi, hdpi, mdpi) may be get cut in small screen(ldpi) so for handling this just create separate Layout folder(layout-small) for it and add ScrollView
(mostly). Thats it.
平板电脑 平板电脑分为两种尺寸.
Tablet Tablets are categorized into two size.
- 7英寸(1024X(600-48(导航栏)))= 1024X552(可绘制大图)
- 10英寸(1280X(800-48(导航栏)))= 1280X752(可绘制x大)
在这种情况下,我们需要为两个屏幕都创建图像,并相应地放置它们
In this we need to create image for both the screen and just put them accordingly
因此,总而言之,我们将在应用程序中拥有此文件夹以支持多屏幕.
So all in all we will have this folder in our application to support multiple screen.
drawable
drawable-ldpi
drawable-mdpi
drawable-hdpi
drawable-xhdpi
drawable-large
drawable-xlarge
将与Screen size and Screen density
drawable-large-ldpi
drawable-large-mdpi
drawable-large-hdpi
drawable-large-xhdpi
具有Screen density and Version
drawable-ldpi-v11
drawable-mdpi-v11
drawable-hdpi-v11
drawable-xhdpi-v11
以及带有Screen size and Version
drawable-large-v11
drawable-xlarge-v11
以及带有Smallest width concept(SW)
drawable-sw???dp
在Android V3.0 Honeycomb中,他们进一步引入了SW(smallest width)
的新概念,其中将设备划分为屏幕宽度,因此,如果我们创建名为drawable-sw360dp
的文件夹,则设备的分辨率为720dp(宽度或高度)将使用此文件夹中的资源.
Further more in Android V3.0 Honeycomb they introduced new concept of SW(smallest width)
in which device are categorized into screen width, so if we are creating a folder named drawable-sw360dp
then the device with 720dp(either width or height) will use resource from the this folder.
例如找到Samsung Galaxy S3
dp 作为后缀 drawable-sw?dp
的后缀
参考 DP计算 ,如果您要支持您的布局或可绘制到S3的图形,则计算结果会显示
for example to find the Samsung Galaxy S3
dp to suffix to drawable-sw?dp
With reference of DP Calculation, If you want to support your layout or drawable to S3 then the calculation says
px =设备的宽度= 720
dpi =设备的密度= 320
公式
px = dp * (dpi / 160)
交换公式,因为我们有px的值
interchanging formula because we have px's value
dp = px / (dpi / 160)
现在投入价值
dp= 720 / (320/160);
dp=360.
所以drawable-sw360dp
会完成工作
从 GsmArena 获取设备配置 同样,您还可以根据Device的Android API版本(即drawable-hdpi-v11`)创建文件夹,以便具有API11且为Hdpi的设备将使用此资源.
Get you Device configuaration from GsmArena Sameway you can also create folder according to Device's Android API version i.e. drawable-hdpi-v11` so the device which is having API11 and it is Hdpi then it will use this resources.
其他提示:
-
使用相对布局,dp,sp和mm
Use relative layouts, dp, sp, and mm
dp单位-在160 ppi屏幕上设备独立像素标准化为1个物理像素,即中等密度.在运行时缩放.用于屏幕元素尺寸
dp units - device independent pixels normalised to 1 physical pixel on a 160 ppi screen i.e. medium density. Scaled at runtime. Use for screen element dimensions
sp单位-基于dp单位的缩放像素,指定为浮点值,但还针对用户的字体大小首选项设置进行缩放.在运行时缩放. 用于字体大小
sp units - scaled pixels, specified as floating point values, based on dp units but additionally scaled for the user's font-size preference setting. Scaled at runtime. Use for font sizes
您应该始终对布局使用RelativeLayout;不建议使用AbsoluteLayout.
使用适当的图像格式-PNG与JPEG
Use appropriate image formats - PNG versus JPEG
Android "prefers" PNG for bitmap image files, "accepts" JPEG, and "discourages" GIF.
但是,PNG和JPEG不是等效的.它们有不同的权衡取舍,PNG并不总是最好的:
However, PNG and JPEG are not equivalents. They have different quality trade offs, and PNG is not always best:
JPEG 与PNG相比最多可减少50%的文件大小,如果您的应用需要大量图像,这是非常重要的
JPEG can offer up to 50% file-size reductions over PNG, which is significant if your app is image-intensive
对于相同的文件大小,高质量的有损" JPEG看起来比高度压缩的无损" PNG更好
A higher quality "lossy" JPEG may look better than a highly compressed "lossless" PNG, for the same file size
在图像和图形中添加标签以进行调试
Add labels to your images and graphics for debugging
使用supports-screens元素
Use the supports-screens element
使用真实的设备值配置仿真器
Configure your emulators with real device values
通常,桌面系统以72ppi(Mac)或96ppi(Windows,Linux)显示.与移动设备相比,台式机显示器始终是低密度的.
Conventionally, desktop systems display at 72ppi (Mac), or 96ppi (Windows, Linux). Compared with mobile, desktop displays are always low density.
始终将您的Android模拟器配置为模拟真实的设备值,并始终将其设置为可缩放以模拟设备密度.
Always configure your Android emulators to mimic real device values, and always set them to scale to emulate device density.
在Eclipse中,可以轻松地创建多个仿真器(从Eclipse菜单栏中选择 Window> AVD Manager> New ),并为其配置真实设备的值:
In Eclipse, it's easy to create multiple emulators (from the Eclipse menu bar, select Window > AVD Manager > New) configured with values for real devices:
为要仿真的真实设备命名仿真器 指定分辨率,不要使用内置通用尺寸 设置设备密度以匹配实际设备(在硬件"窗格中,将抽象的LCD属性"设置为实际密度,始终为整数值)
Name the emulator for the real device it's emulating Specify Resolution, don't use Built-in generic sizes Set the device density to match the real device (in the Hardware pane set Abstracted LCD Property to the real density, always an integer value)
启动设备时,请始终选择将显示比例缩放到实际尺寸,然后以英寸为单位输入实际屏幕尺寸.
When you launch the device, always select Scale display to real size, and type in the real screen dimension in inches.
如果未设置设备密度,则仿真器默认为低密度,并且始终加载ldpi专用资源.分辨率(像素尺寸)将是正确的,但是与密度有关的图像资源将无法按预期显示.
If you don't set the device density, the emulator defaults to low density, and always loads ldpi-specific resources. Resolution (pixel dimensions) will be correct, but your density-dependent image resources will not display as intended.
当然,您所做的任何事情都不会在较低密度的台式机显示器上再现较高密度的图像.
Of course, nothing you do will reproduce higher density image quality on a lower density desktop display.
以下是截至2012年10月1日的7天之内收集的数据.要查看有关Android平台版本的最新统计信息,请
Here is the Data collected during a 7-day period ending on October 1, 2012. To see the latest statistic about Android platform version, go to here
基于屏幕大小
基于屏幕密度
这篇关于应用程序框架可支持多个屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!