Android,图片和dpi [英] Android, images and dpi

查看:372
本文介绍了Android,图片和dpi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android模拟器中使用WVGA800外观,因此密度(hw.lcd.density)为240.我必须在活动视图的底部放置4个图像按钮(每英寸72像素).由于分辨率为480X800,我假设图像的宽度必须为120像素.问题是启动应用程序时,这3个按钮占据了整个宽度,第4个按钮没有位置...然后,我在Fireworks中创建了按钮图像,分辨率为每英寸240像素,宽度为120px,但是问题仍然存在.有人可以解释如何制作正确的可绘制对象(大小和dpi),以便可以在Android上以像素为单位显示它们.

I am using WVGA800 skin in Android emulator, so the density (hw.lcd.density) is 240. I have to put 4 image buttons (72 pixels per inch) at the bottom of activities view. As the resolution is 480X800, I asummed that the width of image must be 120 pixels. The problem is when application is launched, the 3 buttons take all width and there is no place for 4th button... Then I created button image in Fireworks with resolution 240 pixels per inch and in 120px width, but problem remains. Could somebody explain how to make correct drawables (sizes and dpi) so that they can be displayed pixel in pixel on Android?

推荐答案

如果将图片放在res/drawable中,Android会假定它们的分辨率为160dpi,并根据不同的分辨率对其进行缩放.

If you put your images in res/drawable, Android assumes they're for 160dpi and scales them accordingly for different resolutions.

您的选择是将按钮图像放到res/drawable-hdpi中,以表示它们打算用于240dpi左右的密度,或者进入res/drawable-nodpi以使它们不缩放,而与当前屏幕密度无关.

Your options are either to put the button images into res/drawable-hdpi signaling that they're intended for densities around 240dpi, or into res/drawable-nodpi to make them never scale regardless of the current screen density.

您仍然在布局中将它们称为@drawable/whatever,引擎会自动选择最佳匹配项.

You still reference them as @drawable/whatever in layouts, the engine picks the best match automatically.

这篇关于Android,图片和dpi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆