android smart scale
<!DOCTYPE html>
<header><p>Jan 4, 2015 ? CoderSimple <a href="http://codersimple.github.io/android/2015/01/04/android-smart-scale.html">原文傳送陣</a></p> </header><article><p>android 設備的尺寸多種多樣,在適配上給開發者帶來了不少的麻煩,為了讓我們的程序能在不同的屏幕尺寸下優雅的顯示,學習一些適配的知識變得尤為重要,這里為了加深印象,在學習中做下總結(寫到后面感覺沒什么好寫的,都是官網的東西,真矛盾,最后還是當練習排版留下來了)。</p>
- 文字大小屬性使用 sp,其他圖像間距使用 dp,避免使用 px
- 布局盡量使用 wrap_content 和 match_parent 或者 (fill_parent)
- 杜絕使用 AbsoluteLayout 布局(除非特別需要,但是基本不需要)
使用方法:layout-尺寸限定符/最小尺寸限定符/main.xml
- 尺寸限定符(API13 后不推薦使用)
- 最小尺寸限定符(API13 后推薦使用)
- 布局別名 由于最小尺寸限定符在 Android 3.2 及之前平臺上無法識別,有時候在使用最小尺寸限定符布局時為了兼容,有必要再創建一個尺寸限定符的布局,我們可以在尺寸限定符的布局文件夾下在放置一份最小尺寸限定符的布局,然而這樣是我們不愿意做的,這樣會造成內存空間的浪費,因此在里只創建一份文件布局,通過布局的引用達到我們想要的效果,以下為官網示例。 - res/layout/main_twopanes.xml
- res/values-large/layout.xml: <resources><item name="main" type="layout">@layout/main_twopanes</item></resources>
- res/values-sw600dp/layout.xml: <resources><item name="main" type="layout">@layout/main_twopanes</item></resources>
 
屏幕的方向分為水平方向 (land) 和豎直方向 (port),使用方法同布局限定符
layout-尺寸限定符/最小尺寸限定符-方向限定符/main.xml
總而言之,屏幕的適配也就是布局與資源的適配,由于涉及基礎知識較多,造成難度的提升,這里給出 官網屏幕適配教程,所有涉及的知識基本上都有了,只要耐心的看完,相信你會有所收獲。
基礎知識
- small small screens are at least 426dp x 320dp
- normal normal screens are at least 470dp x 320dp
- large large screens are at least 640dp x 480dp
- xlarge xlarge screens are at least 960dp x 720dp
- ldpi(low) ~ 120dpi
- mdpi(medium) ~ 160dpi(base line)
- hdpi(high) ~ 240dpi
- xhdpi(extra-high) ~ 320dpi
- xxhdpi(extra-extra-high) ~ 480dpi
- xxxhdpi(extra-extra-extra-high) ~ 640dpi Note: the drawable-xxxhdpi qualifier is necessary only to provide a launcher icon that can appear larger than usual on an xxhdpi device. You do not need to provide xxxhdpi assets for all your app's images Some devices scale-up the launcher icon by as much as 25%. For example, if your highest density launcher icon image is already extra-extra-high-density, the scaling process will make it appear less crisp. So you should provide a higher density launcher icon in the drawable-xxxhdpi directory, which the system uses instead of scaling up a smaller version of the icon. 
- land(landscape)
- port(portrait)
- The total number of physical pixels on a screen. When adding support for multiple screens, applications do not work directly with resolution; applications should be concerned only with screen size and density, as specified by the generalized size and density groups.
- A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way.
- The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen
- px = dp * (dpi / 160)
screens ranges:
轉載于:https://www.cnblogs.com/codersimple/p/4202398.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的android smart scale的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: win7下安装sourcetree
- 下一篇: Android--百度地图之基础地图(三
