Android支持多屏幕(4)Best Practices

Android支持多屏幕(4)BestPractices

 转载请注明:http://blog.csdn.net/liaoqianchuan00/article/details/23690961

 

参考自:http://developer.android.com/guide/practices/screens_support.html

 

支持多种屏幕是为了让程序在多个Android设备上看起来都漂亮。前面的章节我们介绍了Android是如何适应不同屏幕的,介绍了我们怎么为不同的屏幕来设计不同的UI。这一节我们将介绍一些额外的点。

 

这里是一个快速简要的列表讲解如何保证你的应用程序在不同的屏幕上都显示正确:

 

l   使用wrap_content,fill_parent(match_parent),或者dp来定义你的layout文件

l   在你的程序中不要使用hardcode的像素值

l   不要使用AbsoluteLayout(已经不使用了)

l   为不同的屏幕密度提供不同的图片资源文件

 

下面我们更详细的介绍

 

1.       使用wrap_content,fill_parent(match_parent),或者dp来定义你的layout文件

比如,一个view的layout_width=”100dp”,这就表示在medium-density屏幕上它占用100个像素点,系统会拉伸它到150个像素点在high-density的屏幕上,所以这个view在屏幕上占用的物理空间看起来是一样的。

 

同样的,你应该使用sp来定义文字大小,sp基于用户设置的缩放比例(用户可再设置里面调整字体显示的大小),和dp一样系统会自动缩放字体大小。

 

2.       在你的程序中不要使用hard code 的像素值

因为性能和代码一致性的原因,Android系统使用像素单位来作为标准的定义大小和位置的单位。这就是说,一个view’的大小在代码中总是用像素单位来表达的,但是这是基于当前屏幕密度值的。比如,如果myView.getWidth()返回10,这个view在当前的屏幕上占用10个像素点,但是在一个密度更高的屏幕上他可能会返回15.如果你在你的程序代码中使用像素单位来处理一个没有被pre-scaled的图片,那么你需要scale你的像素值来匹配这个没有scaled的图片资源。

 

3.       不要使用AbsoluteLayout(已经不使用了)

4.       为不同的屏幕密度提供不同的图片资源文件

虽然系统根据当前的屏幕为你缩放了layout和图片,你仍然需要为不同的屏幕大小来细微的调整你的UI,并且为不同的密度的屏幕提供不同的图片。

如果你需要精确的控制你的程序在不同的屏幕上的显示,在不同的限定符的文件夹下调整你的layout和图片。比如,你要在medium和high密度的屏幕上显示一个图标。你需要创建两个不同大小的图片(比如为medium提供的100x100图片和为high提供的150x150的图片),并且把他们放在合适的文件夹下:

 

res/drawable-mdpi/icon.png   //formedium-density screens
res/drawable-hdpi/icon.png   //for high-density screens

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android Best Practices by Godfrey Nolan shows you how to make your Android apps stand out from the crowd with great reviews. Why settle for just making any Android app? Build a brilliant Android app instead that lets your users praise it for ease of use, better performance, and more. Using a series of example apps which gradually evolve throughout this book, Android Best Practices brings together current Android best practices from user interface (UI)/user experience (UX) design, test-driven development (TDD), and design patterns (e.g., MVC) to help you take your app to the next level. In this book you’ll learn how to: Use Android design patterns for consistent UI experience on many devices Use agile techniques such as test-driven development, behavior-driven development, and continuous integration Improve the speed and overall performance of your app Organize an Android app using design patterns such as MVC/MVP Create and consume REST and SOAP web services Designing and developing an app that runs well on many if not all the leading Android smartphones and tablets today can be one of the most daunting challenges for Android developers. Well, this book takes much of the mystery out of that for you. After reading and using Android Best Practices, you’ll become a much better Android app designer and developer, which in turn can make your apps better placed and more successful in the market place. What you’ll learn How to use Android design patterns for consistent UI experience on many devicesHow to use Agile techniques such as Test Driven Development, Behavior Driven Development and Continuous Integration How to test Android APKs on many devices and master device fragmentation Secure coding practices on Android How to organize an Android app using design patterns such as MVC/MVP etc. How to create and consume REST and SOAP web services Who this book is for This book is for Android developers looking to solidify their coding and overall app design and development skill

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值