简体   繁体   English

如何调整图像大小以在Android中呈现相同比例

[英]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.

相关问题 Android如何评估视图大小以在所有设备中保持相同比例 - Android how to evaluate view size to keep same proportion in all devices 如何在任何屏幕尺寸上始终以相同的比例显示Android View的位置和尺寸? - How can I make Android View position and size be shown always with the same proportion on any screen size? Android-缩小图片尺寸不会按相同比例缩小尺寸 - Android - reducing Image dimensions does not reduce size in the same proportion 如何在android中以屏幕宽度显示相同大小的图像 - how to show same size images in equal to width of screen in android Android-压缩和未压缩图像的大小相同 - Android - size of compressed and uncompressed images the same Android布局-将ImageButtons放置在屏幕的相等象限中,并按比例调整它们的大小 - android layout - position ImageButtons in equal quadrants of the screen and size them to proportion 如何使textview的大小与设备的物理大小成比例 - how to make the size of a textview in proportion to the device's physical size 如何下载图像(数千个图像)并在Android的ListAdapter中呈现它们? - How to download Images (thousand of images) and render them in ListAdapter in android? Android ObjectAnimator动画翻译在所有屏幕尺寸上的比例相同 - Android ObjectAnimator animate translationY same proportion on all screen sizes Android对所有不同的屏幕尺寸和分辨率保持相同的比例 - Android maintain same proportion for all different screen sizes and resolution
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM