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 設(shè)備的尺寸多種多樣,在適配上給開發(fā)者帶來了不少的麻煩,為了讓我們的程序能在不同的屏幕尺寸下優(yōu)雅的顯示,學(xué)習(xí)一些適配的知識(shí)變得尤為重要,這里為了加深印象,在學(xué)習(xí)中做下總結(jié)(寫到后面感覺沒什么好寫的,都是官網(wǎng)的東西,真矛盾,最后還是當(dāng)練習(xí)排版留下來了)。</p>
- 文字大小屬性使用 sp,其他圖像間距使用 dp,避免使用 px
- 布局盡量使用 wrap_content 和 match_parent 或者 (fill_parent)
- 杜絕使用 AbsoluteLayout 布局(除非特別需要,但是基本不需要)
使用方法:layout-尺寸限定符/最小尺寸限定符/main.xml
- 尺寸限定符(API13 后不推薦使用)
- 最小尺寸限定符(API13 后推薦使用)
- 布局別名 由于最小尺寸限定符在 Android 3.2 及之前平臺(tái)上無法識(shí)別,有時(shí)候在使用最小尺寸限定符布局時(shí)為了兼容,有必要再創(chuàng)建一個(gè)尺寸限定符的布局,我們可以在尺寸限定符的布局文件夾下在放置一份最小尺寸限定符的布局,然而這樣是我們不愿意做的,這樣會(huì)造成內(nèi)存空間的浪費(fèi),因此在里只創(chuàng)建一份文件布局,通過布局的引用達(dá)到我們想要的效果,以下為官網(wǎng)示例。
- 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
總而言之,屏幕的適配也就是布局與資源的適配,由于涉及基礎(chǔ)知識(shí)較多,造成難度的提升,這里給出 官網(wǎng)屏幕適配教程,所有涉及的知識(shí)基本上都有了,只要耐心的看完,相信你會(huì)有所收獲。
基礎(chǔ)知識(shí)
- 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:
轉(zhuǎn)載于:https://www.cnblogs.com/codersimple/p/4202398.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的android smart scale的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: win7下安装sourcetree
- 下一篇: Android--百度地图之基础地图(三