你如何开始开发多种设备尺寸/密度的Andr​​oid应用程序? [英] How do you begin developing an Android app for multiple devices sizes/densities?

查看:157
本文介绍了你如何开始开发多种设备尺寸/密度的Andr​​oid应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问过一个类似的问题,但想到我会问一个更普遍的问题得到更广泛的投入。

I've asked a question similar to this but thought I would ask a more general question to get a wider range of input.

我问这个问题,因为我已经开发了近两年的应用程序,我把所有的图像资源,绘制,华电国际文件夹中,没有处理好风景模式,测试它主要是对我个人的Droid手机,基本上觉得我是只开发自己的设备。我虽然一直使用的DPI和SP在适当的地方,这是不够的,我的应用程序,以适当的比例在其他屏幕尺寸/密度。它缩放没关系有时,但总是趋于切断屏幕的一部分上较小的尺寸。

I ask this question because the last two apps I've developed, I threw all image resources in the drawable-hdpi folder, didn't deal with landscape-mode, tested it mainly on my own personal Droid phone, and basically felt like I was only developing for my own device. Although I did always use dpi and sp in the appropriate places, this was not enough for my app to scale appropriately on other screen sizes/densities. It scaled okay sometimes, but would always tend to cut off a portion of the screen on smaller sizes.

什么是开始一个应用程序,将规模至少在某种程度上也对所有设备的最佳方法是什么?

What are the best ways to begin an app that will scale at least somewhat well on all devices?

例如,我要建立我的应用程序的布局,使它看起来默认的HVGA屏幕上正确,并允许它扩展到更大的密度?难道是一个最佳实践,积极构建纵向和横向布局文件?

For example, should I construct my app layouts so that it looks correct on the default HVGA screen and allow it to scale to larger densities? Would it be a best practice to be actively building both portrait and landscape layout files?

你在做什么,以确保您的应用程序看起来不错,在所有设备上,而不只是专注在一个尺寸,然后争先恐后稍后左右的管理呢?

What are you doing to ensure your apps look nice on all devices without just focusing on one size and then scrambling around later to manage this?

推荐答案

我公司始终遵循这些规则:

I always follow those rules:

  • 设置一切从支持屏来真。 Android将知道你是准备好每一个屏幕环境中,你就会知道,它没有任何屏幕虚拟化。例如:即使您的设备具有大尺寸屏幕,你的code会看到它作为一个正常大小的屏幕
  • 请不要使用固定大小的宽度和高度。如果你必须使用DP作为虚拟像素。使用WRAP_CONTENT和FILL_PARENT。 DP是在屏幕上用160dpi的物理像素。如果您的应用程序在设备低/高密度运行,Android将重新计算这个给你。
  • 使用DP为单位的字体大小。
  • 尝试相对做的一切。 U可以使用RelativeLayout的,如果你想有等,如果你需要的百分比,你可以使用的LinearLayout下的另一种东西。
  • 使用九pathes作为背景。
  • 确保你把资源投入到正确的绘制/布局文件夹。
  • set everything from supports-screens to true. Android will know that you are ready for every screen environment and you will know that it doesn't make any screen virtualization. For example: even if your device has big-size screen, your code will see it as a normal-size screen
  • don't use fixed sizes for width and height. If you must, use "dp" as a virtual pixel. use WRAP_CONTENT and FILL_PARENT. "dp" is a physical pixel on screen with 160 dpi. If your app runs on device with lower/higher density, android will recalculate this for you.
  • use "dp" as a unit for font size.
  • try to do everything relatively. U can use RelativeLayout if you want to have "something under another" etc. If you need percentages you can use LinearLayout.
  • use nine-pathes as a background.
  • make sure that you put resources into correct drawable/layout folders.

关 - 当然,这并不是每一个项目最好的方法:)有时UI设计者希望一些额外的:]

Off-course, this is not best approach for every project :) Sometimes UI designer wants some extra :]

这篇关于你如何开始开发多种设备尺寸/密度的Andr​​oid应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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