lesson 2 Supporting Different Devices

Supporting Different Devices

1 Supporting Different Languages支持不同的语言

To add support for more languages, create additional values directories inside res/ that include a hyphen and the ISO language code at the end of the directory name. For example, values-es/ is the directory containing simple resourcess for the Locales with the language code “es”. Android loads the appropriate resources according to the locale settings of the device at run time. For more information, see Providing Alternative


For example    

MyProject/
res/
   values/
       strings.xml
   values-es/
       strings.xml
   values-fr/
       strings.xml

2 Supporting Different Screens支持不同的屏幕

Android categorizes device screens using two general properties: size and density

2.1 There are four generalized sizes: small, normal, large, xlarge

Each layout should be saved into the appropriate resources directory, named with a -<screen_size> suffix


MyProject/
res/
    layout/              # default (portrait)
        main.xml
    layout-land/         # landscape
        main.xml
    layout-large/        # large (portrait)
        main.xml
    layout-large-land/   # large landscape
        main.xml

Note: Android 3.2 and above supports an advanced method of defining screen sizes that allows you to specify resources for screen sizes based on the minimum width and height in terms of density-independent pixels. This lesson does not cover this new technique. For more information, read Designing for Multiple Screens.

2.2 And four generalized densities: low (ldpi), medium (mdpi), high (hdpi), extra high (xhdpi)
  • xhdpi: 2.0
  • hdpi: 1.5
  • mdpi: 1.0 (baseline)
  • ldpi: 0.75

MyProject/
res/
    drawable-xhdpi/
        awesomeimage.png
    drawable-hdpi/
        awesomeimage.png
    drawable-mdpi/
        awesomeimage.png
    drawable-ldpi/
        awesomeimage.png

3 Supporting Different Platform Versions支持不同的android版本

  • 3.1 Specify Minimum and Target API Levels

  • 3.2 Check System Version at Runtime


private void setUpActionBar() {
// Make sure we're running on Honeycomb or higher to    use ActionBar APIs
    if (Build.VERSION.SDK_INT >=    Build.VERSION_CODES.HONEYCOMB) {
        ActionBar actionBar = getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
}
  • 3.3 Use Platform Styles and Themes
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值