[英]How to size images to render the same proportion in Android
I have a design concept that I need to create. 我有一个需要创建的设计概念。 It was designed in a given resolution: 480x800.
它以给定的分辨率:480x800设计。 It contains a box with the width of 390px that has to be horizontally aligned in the middle.
它包含一个宽度为390px的框,该框必须在中间水平对齐。 So there are 45 pixels left in both sides.
因此,两侧都剩下45个像素。
When I create the layout in Android, I have to give the box width in dp. 当我在Android中创建布局时,必须以dp给出框的宽度。 So I use a dp->px calculator and check what numbers it shows.
因此,我使用dp-> px计算器并检查显示的数字。 It tells me, I have to set the width 252dp to make the box be 390px wide in a hdpi, 480x800 phone.
它告诉我,我必须设置252dp的宽度,以使该框在480x800的hdpi手机中为390px宽。 When I set it, and starts the emulator, it shows the proportions all right.
当我设置它并启动模拟器时,它会正确显示比例。
<EditText
android:id="@+id/txtBox"
android:layout_width="262dp"
android:layout_height="37dp"
/>
I change the emulator to a 720x1280, hdpi. 我将模拟器更改为720x1280,hdpi。 What width will the box have?
盒子有什么宽度? Will it be 252 dp (390px)?
会是252 dp(390像素)吗? If so, the box will take up only half of the screen and my proportion will be off.
如果是这样,则该框将仅占据屏幕的一半,而我的比例将关闭。
How should I set the image width and size to create the right proportions? 如何设置图像的宽度和尺寸以创建正确的比例? What will make it dynamic?
是什么使它充满活力?
Images in android are difficult to deal with. android中的图像很难处理。 Due to the resolution factor images in one device seems a different in proportions than other devices.
由于分辨率因素,一台设备中的图像比例似乎与其他设备不同。 The solution is to use appropriate images for appropriate screen density.
解决方案是使用适当的图像以获得适当的屏幕密度。 See iconography on developer site.
请参阅开发者网站上的图像。 By providing alternate resources in folder's like drawable-hdpi you ensure that they are rendered properly.
通过在诸如drawable-hdpi之类的文件夹中提供备用资源,可以确保它们被正确渲染。 Also as a good programming practice use wrap_content or match_parent as our layout_width or height.
同样好的编程习惯,请使用wrap_content或match_parent作为我们的layout_width或height。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.