android-supporting-multiple-devices

There are a few common questions asked whenever development begins on a new Android app. What assets will be needed? Which devices should be supported and how many can be supported with the team’s available resources? As an Android developer, my goal is to support the majority of devices and reach the broadest audience.
Specifically, when developing a UI for an Android app, the team must consider assets (backgrounds, buttons, etc.) and layouts (the actual XML UI code). To develop the app efficiently, we want to create the lowest multiple of assets while still supporting a wide range of devices. We also want to avoid having to creating the same layout more than once.
When I first began looking into this, I searched the Internet for best practices for supporting as many devices as possible without having to reproduce the same assets multiplied by the growing number of Android devices. Internet documentation seemed to lack any direct answers. I felt a growing concern that the Android architecture was rigid, and that every asset/layout would have to be perfectly defined for every resolution we wanted to support. This could have been ridiculously time consuming.
However, after further research I discovered that Android architecture was actually rather robust. If properly prepared, it was relatively simple for a developer to handle current and future Android devices. This is how it breaks down: when dealing with Android devices we are worried about more than just the resolution, we need to know the Dots Per Inch (DPI). The DPI is the number of individual dots that can be placed in a line within the span of 1 inch. DPI is considered more important than resolution because Android devices come in so many shapes and sizes. Devices are usually grouped by size or by DPI.
I found it easiest to work with the DPI groupings:
Devices Categorized by Dots Per Inch (DPI), Source: http://developer.android.com/guide/practices/screens_support.html
As you can see, the DPI ranges are overlapping. I recommend generalizing the ranges by the following values:
- low-dpi = 120
- med-dpi = 160
- high-dpi = 240
- extra high-dpi = 320
These groups also share generally the same relative aspect ratio. Below is a table of the most common screen configurations.
Common Android Device Screen Configurations, Source: http://developer.android.com/guide/practices/screens_support.html
Which DPIs should you support? Here is a great way to decide:http://developer.android.com/resources/dashboard/screens.html
Let’s say you have decided you want to support low, medium and high density devices. How will you create, for example, a background image? How are we going to support all low density devices when in the table above there are 6 different low-dpi resolutions listed? This is whereNine-Patch images come into play. Nine-patch images allow you to define the stretchable areas of a bitmap so that if your bitmap doesn’t already fill a space Android will stretch only these areas to fill the space.
When using Nine-Patch images I would suggest using the lowest resolution so that the image always has room to grow when adjusting for other resolutions.
- Low-dpi (240×320) at 120 dpi
- Med-dpi (320×480) at 160 dpi
- High-dpi (480×800) at 240 dpi
Now that we have these images, where do we put them? Android has many configuration qualifiers to allow the system to select to correct asset for a device. In this example we would have 4 folders:
- drawable-ldpi
- drawable-mdpi
- drawable-hdpi
- drawable-nodpi
In each we would have the corresponding “background.png” which we reference only once in our layout code and Android takes care of which folder to grab the image from.
When dealing with an asset like a button image it is best to use medium DPI as your baseline. Then define your low and high asset sizes as a factor of the medium DPI asset.
- Low DPI – 75% Size (120 dpi)
- Med DPI – 100% Size (160 dpi)
- High DPI – 150% Size (240 dpi)
When it comes to layouts in most cases, it works to use one layout file for all resolutions. This works because we define the dp (density-independent pixel) size of the UI elements in our layout. This way the layout scales nicely when switching densities. There are cases where layouts must be defined for each density. This is due to the physical screen size between devices varying too much. It is also possible to apply the ldpi/mdpi/hdpi configuration qualifiers to the layout folders.
It’s impossible to test your app on every device so be sure to use the emulator extensively to test your assets and layouts.
By applying these steps, your app can efficiently support the majority of Android devices. Good
android-supporting-multiple-devices的更多相关文章
- Android官方文档翻译 十二 3.Supporting Different Devices
Supporting Different Devices 支持不同设备 Dependencies and prerequisites 依赖关系和先决条件 Android 1.6 or higher A ...
- Supporting Multiple Screens 翻译 支持各种屏幕(上)
Supporting Multiple Screens 支持各种各样的屏幕尺寸.屏幕密度 Android runs on a variety of devices that offer differe ...
- adb错误:Failed to execute android command 'adb devices'.
好吧,我是用的phonegap3.0开发的,很简单,安装的时候一句phonegap run android –device就可以了(-device参数非必要,我是为了不跑模拟器,加上此参数限制只跑到设 ...
- 【读书笔记】https://source.android.google.cn/devices/bootloader
https://source.android.google.cn/devices/bootloader 本文主要记录aosp官网关于bootloader的相关资料 Bootloader A bootl ...
- Supporting Multiple Versions of WebSocket Protocol 支持多版本WebSocket协议
https://tools.ietf.org/html/rfc6455#section-4.4 4.4. Supporting Multiple Versions of WebSocket Proto ...
- Android调试adb devices找不到设备【转】
adb驱动已经安装成功,但是adb devices却无法找到设备,USB大容量存储也是正常: 以前如果出现此种情况,我能想到的原因如下: 1.杀毒软件问题(关闭MacAfee) 2.驱动安装有误,重新 ...
- [Android问答] px、dp和sp,这些单位有什么区别?
相信每个Android新手都会遇到这个问题,希望这篇帖子能让你不再纠结. px: 即像素,1px代表屏幕上一个物理的像素点: px单位不被建议使用,因为同样100px的图片,在不同手机上显示的实际大小 ...
- Android开发中dp、dpi、px的区别(转)
一.基本概念 - dp:安卓中的相对大小 - dpi:(dot per inch)每英寸像素多少 - px:像素点 二.详细说明 1.px和dpi - px: 平常所说的1920×1080只是像素数量 ...
- Android 图片文字单位 px、dp、sp区别
文章来源:http://www.cnblogs.com/bjzhanghao/archive/2012/11/06/2757300.html px:像素,一个像素点,1px代表屏幕上一个物理的像素点: ...
- px、dp、sp、mm、in、pt这些单位有什么区别?
相信每个Android新手都会遇到这个问题,希望这篇帖子能让你不再纠结. px: 即像素,1px代表屏幕上一个物理的像素点: px单位不被建议使用,因为同样100px的图片,在不同手机上显示的实际大小 ...
随机推荐
- Oracle EBS-SQL (PO-9):检查期间采购订单执行情况.sql
--采购订单执行情况查询(七天内接收情况)select pha.segment1 采购订单, msib.segment1 物料编码, pla.qu ...
- 关于oracle的certview
前两天去参加oracle 11g 的两门考试(1Z0-051和1Z0-052),在家看了好几遍题库,我本来想着上午一门,下午考一门,但是我嫌着麻烦,就预约一下午考完两门.在考试完一门后,发现成绩不 ...
- 微软Code Hunt答案(00-05)——沉迷娱乐的我
昨天看到微软出的网游Code Hunt.o(∩_∩)o...哈哈,还不好好玩一吧,个人感觉不是一个模块比一个模块难的,Code Hunt是按功能划分.所以不要怕自己做不来.由于不同人特长不一样. 像A ...
- 正式生产环境下hadoop集群的DNS+NFS+ssh免password登陆配置
博客地址:http://www.loveweir.com/ 环境虚拟机centos6.5 主机名h1 IP 192.168.137.11 作为DNS FNS的server 主机名h2 IP 19 ...
- c#常见操作
1. StreamWriter - 文件写入类StreamWriter s = new StreamWriter(address + "/Menu.ini", true);s.Wr ...
- Oracle初级入门 根据某字段重复只取一条记录,并计计算重复条数
在平常开发中,去重复数据经常使用到,本人新手,接触Oracle也不久,开发中用到的小知识点,记录一下,老鸟可绕道,如果有写错的,请指正. 去重复记录可以使用distinct,当只查询一列数据时,可以轻 ...
- CSS技巧和犯错点总结
4.14 CSS background属性简写: background-position属性组合方式:[ left | center | right ] || [ top | bottom ] (组 ...
- JavaScript 中的面向对象的初步认识
我在学习JS的面向对象编程的时候,总是有两个奇怪的问题. 第一个就是:面向对象在JS中很少用到... 可能是目前自己做的项目还是比较简单,前端方面的任务我几乎都是用面向过程的方式写的,所以就导致,我啃 ...
- nutch2.3中nutch-site.xml设置说明
nutch-site.xml是运行nutch的非必须设置文件,也就是说你不设置,nutch照样可以运行. nutch-site.xml是nutch-default.xml的一个客制化文件. nutch ...
- Manacher 算法
Manacher算法用于求回文子串,它的复杂度为O(n). 这个算法有一个很巧妙的地方,它把奇数的回文串和偶数的回文串统一起来考虑了.在相邻的两个字符之间加进一个分隔符 '#' ,串的首尾也要加. 原 ...