首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android 机型适配之银屏适配

2013-02-05 
Android 机型适配之屏幕适配Supporting Different ScreensPREVIOUSNEXTNote:?Android automatically scale

Android 机型适配之屏幕适配

Supporting Different ScreensPREVIOUSNEXTNote:?Android automatically scales your layout in order to properly fit the screen. Thus, your layouts for different screen sizes don't need to worry about the absolute size of UI elements but instead focus on the layout structure that affects the user experience (such as the size or position of important views relative to sibling views).

For example, this project includes a default layout and an alternative layout for?large?screens:

@Overrideprotectedvoid onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);     setContentView(R.layout.main);}

The system loads the layout file from the appropriate layout directory based on screen size of the device on which your app is running. More information about how Android selects the appropriate resource is available in the?Providing Resources?guide.

As another example, here's a project with an alternative layout for landscape orientation:

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.

Create Different Bitmaps

You should always provide bitmap resources that are properly scaled to each of the generalized density buckets: low, medium, high and extra-high density. This helps you achieve good graphical quality and performance on all screen densities.

To generate these images, you should start with your raw resource in vector format and generate the images for each density using the following size scale:

  • xhdpi: 2.0
  • hdpi: 1.5
  • mdpi: 1.0 (baseline)
  • ldpi: 0.75

    This means that if you generate a 200x200 image for xhdpi devices, you should generate the same resource in 150x150 for hdpi, 100x100 for mdpi, and 75x75 for ldpi devices.

    Then, place the files in the appropriate drawable resource directory:

    Note:?Low-density (ldpi) resources aren’t always necessary. When you provide hdpi assets, the system scales them down by one half to properly fit ldpi screens.

    For more tips and guidelines about creating icon assets for your app, see the?Iconography design guide.

热点排行