TextViewに.png画像を表示したい。タブレットを使用する人、スマートフォンを使用する人がいますが、画面に比例した画像を表示するにはどうすればよいですか?別の画像を作成して、コードで次のようなものを使用する必要がありますかif(screen == smartphone) setView(Png1.png)
?
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.
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