问题描述
我想在TextView的显示PNG图片。有人会用平板电脑,有人会用智能手机,我怎么能显示图像成正比的屏幕?我一定要创造出不同的图像,并在code像如果(大屏幕==智能手机)的setView(Png1.png)
?
I want to display .png image on TextView. Someone will use tablet, someone will use smartphone, how can I show an image proportional to the screen? Do I have to create different images and use in the code something like if(screen == smartphone) setView(Png1.png)
?
推荐答案
有,当你设计一个应用程序,它结果这需要采取照顾两个重要参数
应该在多种设备上运行:结果
There are two important parameters which needs to taken cared when you are designing an app which
should run on multiple devices:
- 的大小(设备的物理尺寸)
- 设备的密度
尺寸:在Android设备的大小没有被定义为一个独特的物理价值,但作为一个范围结果。
它们是:小,中,大,XLARGE结果
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.
密度:密度也被定义为一个范围搜索。
它们是:LDPI,MDPI,华电国际和xhdpi
Density: Density is also defined as a range.
These are: ldpi, mdpi, hdpi and xhdpi.
为了处理大小,你需要使用有多种布局,一个是大小的每一类,你需要使用不同的DP值的高度和意见宽度为每个布局的sizeof的小型和大型设备不会相同。
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的低密度(放置在绘制-LDPI)
- 48×48的中密度(放置在绘制-MDPI)
- 72x72不等#高密度(放置在绘制 - 华电国际)
- 96x96的额外高密度(放置在绘制-xhdpi)
有关决议这种变化的比例为3:4:6:8(LDPI:MDPI:华电国际:xhdpi)结果
The ratio for this variation of the resolution is 3:4:6:8(ldpi:mdpi:hdpi:xhdpi)
有关进一步阅读,你可以参考这个Android开发者的链接:结果
For further reading you can refer to this android developer's link:
http://developer.android.com/guide/practices/screens_support.html
这篇关于如何显示正比于屏幕的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!