1

我写了一个android应用程序,但我发现应用程序的图形在不同尺寸的android手机中具有不同的性能。有些图形甚至会在平板电脑中变得非常糟糕。因此,我想知道如何调整程序代码,使应用程序可以自动适应安卓手机和平板电脑的不同大小。谢谢!

4

3 回答 3

1

There are two important parameters which needs to taken cared when you are designing an app which
should run on multiple devices:

  • size(physical size of the device)
  • density of the device

Size: Size of a device in android is not defined as a unique physical value but as a range.
These are: small, normal, large and xlarge.

Density: Density is also defined as a range.
These are: ldpi, mdpi, hdpi and xhdpi.

enter image description here

For handling size you need to use have multiple layouts, one for each category of the size and you need to use different dp value for the height and width of the views for each of the layout as the sizeof a small and a large device will not be same.

For handling density you need to using different drawables for different screen densities i.e you need to place different density drawables in different drawable folders.
Eg:
These are the resolutions for a particular drawable

  • 36x36 for low-density (placed in drawable-ldpi)
  • 48x48 for medium-density (placed in drawable-mdpi)
  • 72x72 for high-density (placed in drawable-hdpi)
  • 96x96 for extra high-density (placed in drawable-xhdpi)

The ratio for this variation of the resolution is 3:4:6:8(ldpi:mdpi:hdpi:xhdpi)

For further reading you can refer to this android developer's link:
http://developer.android.com/guide/practices/screens_support.html

于 2012-08-22T08:31:45.697 回答
0

在 xml 布局中使用WaitSum 。

Waitsum 会自动设置不同尺寸密度的布局和视图。

于 2012-08-22T09:41:41.457 回答
0
  1. 使用相对布局
  2. 为每个密度准备图形(ldpi、mdpi、hdpi、xhdpi)
  3. 九个补丁你的图形。
于 2012-08-22T08:05:08.973 回答