Android Configuration介绍 (未完成)

博客很空,想赶紧填一篇东西,选的这个题目看了下中文网络中还不是很常见,但是由于我也不了解全部的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 Configuration介绍 (未完成),布布扣,bubuko.com

Android Configuration介绍 (未完成)

上一篇:Android 自定义 ViewPager 打造千变万化的图片切换效果


下一篇:Android surfaceview详解