Android資源目錄的讀取順序

重點(diǎn)討論跟屏幕分辨率相關(guān)的資源匹配

屏幕分辨率相關(guān)的qualifier如下:

  • avaiable width, 比如 w720dp

When your application provides multiple resource directories with different values for this configuration, the system uses the one closest to (without exceeding) the device's current screen width.

  • avaiable heigth, 比如 h720dp

When your application provides multiple resource directories with different values for this configuration, the system uses the one closest to (without exceeding) the device's current screen heigth.

  • Screen Size: small, normal, large, xlarge

Note: Using a size qualifier does not imply that the resources are only for screens of that size. If you do not provide alternative resources with qualifiers that better match the current device configuration, the system may use whichever resources are the best match.
Caution: If all your resources use a size qualifier that is larger than the current screen, the system will notuse them and your application will crash at runtime (for example, if all layout resources are tagged with the xlarge
qualifier, but the device is a normal-size screen).

  • Screen pixel density (dpi), hdpi, xhdpi, ... etc

The system uses the appropriate alternative resourceBased on the size and density of the current screen, the system uses any size- and density-specific resource provided in your application. For example, if the device has a high-density screen and the application requests a drawable resource, the system looks for a drawable resource directory that best matches the device configuration. Depending on the other alternative resources available, a resource directory with the hdpi
qualifier (such as drawable-hdpi/
) might be the best match, so the system uses the drawable resource from this directory.
If no matching resource is available, the system uses the default resource and scales it up or down as needed to match the current screen size and densityThe "default" resources are those that are not tagged with a configuration qualifier. For example, the resources in drawable/
are the default drawable resources. The system assumes that default resources are designed for the baseline screen size and density, which is a normal screen size and a medium-density. As such, the system scales default density resources up for high-density screens and down for low-density screens, as appropriate.
However, when the system is looking for a density-specific resource and does not find it in the density-specific directory, it won't always use the default resources. The system may instead use one of the other density-specific resources in order to provide better results when scaling. For example, when looking for a low-density resource and it is not available, the system prefers to scale-down the high-density version of the resource, because the system can easily scale a high-density resource down to low-density by a factor of 0.5, with fewer artifacts, compared to scaling a medium-density resource by a factor of 0.75.

mipmap vs drawable folders

The mipmap folders are for placing your app/launcher icons (which are shown on the homescreen) in only. Any other drawable assets you use should be placed in the relevant drawable folders as before.
According to this Google blogpost:
It’s best practice to place your app icons in mipmap- folders (not the drawable- folders) because they are used at resolutions different from the device’s current density.
When referencing the mipmap- folders ensure you are using the following reference:
android:icon="@mipmap/ic_launcher"
The reason they use a different density is that some launchers actually display the icons larger than they were intended. Because of this, they use the next size up.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子量愧,更是在濱河造成了極大的恐慌灯帮,老刑警劉巖肪虎,帶你破解...
    沈念sama閱讀 212,222評論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件做瞪,死亡現(xiàn)場離奇詭異契讲,居然都是意外死亡畸裳,警方通過查閱死者的電腦和手機(jī)缰犁,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,455評論 3 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來怖糊,“玉大人帅容,你說我怎么就攤上這事∥樯耍” “怎么了并徘?”我有些...
    開封第一講書人閱讀 157,720評論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長扰魂。 經(jīng)常有香客問我麦乞,道長,這世上最難降的妖魔是什么劝评? 我笑而不...
    開封第一講書人閱讀 56,568評論 1 284
  • 正文 為了忘掉前任姐直,我火速辦了婚禮,結(jié)果婚禮上蒋畜,老公的妹妹穿的比我還像新娘简肴。我一直安慰自己,他們只是感情好百侧,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,696評論 6 386
  • 文/花漫 我一把揭開白布砰识。 她就那樣靜靜地躺著,像睡著了一般佣渴。 火紅的嫁衣襯著肌膚如雪辫狼。 梳的紋絲不亂的頭發(fā)上够傍,一...
    開封第一講書人閱讀 49,879評論 1 290
  • 那天扎附,我揣著相機(jī)與錄音,去河邊找鬼佩耳。 笑死砂竖,一個(gè)胖子當(dāng)著我的面吹牛真椿,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播乎澄,決...
    沈念sama閱讀 39,028評論 3 409
  • 文/蒼蘭香墨 我猛地睜開眼突硝,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了置济?” 一聲冷哼從身側(cè)響起解恰,我...
    開封第一講書人閱讀 37,773評論 0 268
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎浙于,沒想到半個(gè)月后护盈,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,220評論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡羞酗,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,550評論 2 327
  • 正文 我和宋清朗相戀三年腐宋,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片檀轨。...
    茶點(diǎn)故事閱讀 38,697評論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡胸竞,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出裤园,到底是詐尸還是另有隱情撤师,我是刑警寧澤,帶...
    沈念sama閱讀 34,360評論 4 332
  • 正文 年R本政府宣布拧揽,位于F島的核電站剃盾,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏淤袜。R本人自食惡果不足惜痒谴,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,002評論 3 315
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望铡羡。 院中可真熱鬧积蔚,春花似錦、人聲如沸烦周。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,782評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至漱贱,卻和暖如春槐雾,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背幅狮。 一陣腳步聲響...
    開封第一講書人閱讀 32,010評論 1 266
  • 我被黑心中介騙來泰國打工募强, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人崇摄。 一個(gè)月前我還...
    沈念sama閱讀 46,433評論 2 360
  • 正文 我出身青樓擎值,卻偏偏與公主長得像,于是被迫代替她去往敵國和親逐抑。 傳聞我的和親對象是個(gè)殘疾皇子鸠儿,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,587評論 2 350

推薦閱讀更多精彩內(nèi)容

  • Correctness AdapterViewChildren Summary: AdapterViews can...
    MarcusMa閱讀 8,855評論 0 6
  • 1.探索重要的事情 前兩天貓叔推薦我們看關(guān)于時(shí)間管理的TED演講視頻。對我感觸最深的就是那個(gè)家庭主婦家里的自來水管...
    houpanpan926閱讀 294評論 0 0
  • “我們要的作品泵肄,要創(chuàng)新捆交,要有功能,要解決消費(fèi)者的問題腐巢∑纷罚” 這是我們老師經(jīng)常念叨的一句話。 我今天想說的就是冯丙,這里面...
    煙老師閱讀 415評論 0 0
  • 大增益_漠雨閱讀 454評論 0 0
  • 每每這樣的時(shí)候肉瓦,我就會想到:有沒有他,都是一樣的胃惜。體諒他不舒服泞莉,可他睡一覺起來玩手機(jī)。平時(shí)船殉,也是玩手機(jī)鲫趁。好...
    Zeteo閱讀 157評論 0 0