Android Configuration介紹 (未完成),android介紹
部落格很空,想趕緊填一篇東西,選的這個題目看了下中文網路中還不是很常見,但是由於我也不瞭解全部的configuration,需要驗證思路,寫起來也很慢,先發個未完成的佔座。
所謂Configuration指的是Configuration.java這個類所代表的配置資訊,它的位置在($ANDROID_ROOT)/frameworks/base/core/java/android/content/res/Configuration.java
本文分三部分:
一. 逐一講解成員變數,瞭解功能和每一個數值代表的含義;
二. 追尋configuration的初始化和被使用的過程;
三. 總結作為一個Android平台維護者怎麼配置這些數值。
一. 成員變數
public int densityDpi //The target screen density being rendered to, corresponding to density resource qualifier.
目前一般是一個3位元的10進位數,分別對應著:
120 –> ldpi: Low-density screens.
160 –> mdpi: Medium-density (on traditional HVGA) screens.
240 –> hdpi: High-density screens.
320 –> xhdpi: Extra high-density screens.
之後還有更大的xxhdpi(480)和xxxhdpi(640),densityDpi越大,代表當前裝置的螢幕解析度(dpi,dot per inch)越高,一個裝置的densityDpi在出廠時已根據裝置螢幕dpi決定了;假設我現在有一個MX3,1800 × 1080 resolution,5.1 inches,那麼它的dpi就是對角線的像素點數除以5.1約等於411.6,我把densityDpi配置成與411.6最接近的xxhdpi。它的作用在於讓app在不知道每一款Android裝置的螢幕大小和解析度的情況下,可以通過densityDpi動態決定載入什麼資源,從而適配這些裝置。
比如在畫UI的時候一般用dp做單位,系統會幫忙縮放,在不同解析度的裝置上視覺上會有相同的大小;而用pixel做單位就只有固定pixel的大小,相同pixel大小的view在高解析度的裝置上視覺上就相對顯得小。這裡就用到的pixel和dp的轉換:
dp= px*160/densityDpi;
另外app的res目錄下會有一些drawable-mdpi/drawable-hdpi/drawable-xhdpi,也是通過densityDpi來決定的,當然這些目錄的分法更複雜一點,這裡就不多說了。
public float fontScale //Current user preference for the scaling factor for fonts, relative to the base density scaling.
public int hardKeyboardHidden
A flag indicating whether the hard keyboard has been hidden.
public int keyboard
The kind of keyboard attached to the device.
public int keyboardHidden
A flag indicating whether any keyboard is available.
public Locale locale
Current user preference for the locale, corresponding to locale resource qualifier.
public int mcc
IMSI MCC (Mobile Country Code), corresponding to mcc resource qualifier.
public int mnc
IMSI MNC (Mobile Network Code), corresponding to mnc resource qualifier.
public int navigation
The kind of navigation method available on the device.
public int navigationHidden
A flag indicating whether any 5-way or DPAD navigation available.
public int orientation
Overall orientation of the screen.
public int screenHeightDp
The current height of the available screen space, in dp units, corresponding to screen height resource qualifier.
public int screenLayout
Bit mask of overall layout of the screen.
public int screenWidthDp
The current width of the available screen space, in dp units, corresponding to screen width resource qualifier.
public int smallestScreenWidthDp
The smallest screen size an application will see in normal operation, corresponding to smallest screen width resource qualifier.
public int touchscreen
The kind of touch screen attached to the device.
public int uiMode
Bit mask of the ui mode.
android編程時eclipse的run as不好用 只彈出configuration 還不可以自動綁定模擬器 大蝦指點
哦,這個問題啊,因為你是分2次啟動的,第一啟動的時候android模擬器會安裝你的api,也就是那個hello world程式,你這個時候關閉了android模擬器,然後修改你的程式改成hellowold,再運行,這個時候模擬器因為已經安裝了第一個api就是那個有空格的應用,所以第二次安裝就不會成功,所以也不會運行,如果你沒有關閉android模擬器,而是直接修改然後運行,就不會有這個問題,解決方案是刪除模擬器裡面已經安裝過的那個api,再運行你第二個沒有空格的helloworld就會出現
android螢幕轉換監聽的調用public void onConfigurationChanged(Configuration config) 次數的問題?
看下這個吧我匯總的:Android橫豎切屏注意事項
hi.baidu.com/...e.html