Android Widget 位图尺寸
你好,
我正在编写一个小部件,但不确定使用什么大小的位图作为每个屏幕分辨率/密度的背景。
根据Android Developer App Widgets教程:
To find your minimum width and height in density-independent pixels (dp), use this formula:
(number of cells * 74) - 2
Following this formula, you should use 72 dp for a height of one cell, 294 dp and for a width of four cells
所以如果我的小部件是 72dp x 294dp,我的 ldpi、mdpi 和 hdpi 可绘制对象需要多大尺寸的位图?
另外,我的清单中是否需要任何特定的支持屏幕设置?
TIA,
-Frink
更新: 我为每个可绘制文件夹制作了一些不同尺寸和颜色的棋盘图案并进行了尝试。这个密度问题是不是有点转移注意力?
我刚刚完成了以 HVGA、中等密度、320x480 运行的模拟器的屏幕抓取。我的小部件占用的大小是 320x100,因此我在 mdpi 文件夹中创建一个 320x100 位图作为我的小部件的背景,它在我的模拟器和 LG GT540 上看起来都很完美。
对于以 WVGA854、高密度、480x854 运行的模拟器。我的小部件的大小是 480x150。创建此尺寸的背景并将其放置在 hdpi 文件夹中可以在此模拟器上正确显示。我没有硬件可以对此进行测试:-(
Update2: 我想我现在可以更好地解释我的问题了:-)
如果我有三个设备:
Device1, resolution 320x480, density ldpi
Device2, resolution 320x480, density mdpi
Device3, resolution 400x854, density mdpi
屏幕的物理尺寸可能都会不同,但我认为实际尺寸并不重要
我已经计算出Device1和Device2会需要 320x100 的背景,而 Device3 需要 400x150 那么 mdpi 文件夹中的背景大小要多大才能在 Device2 和 Device3 上正确显示?
Hallo,
I am writing a widget, but am unsure what size bitmap to use as a background for each screen resolution/density.
According to the Android Developer App Widgets tutorial:
To find your minimum width and height in density-independent pixels (dp), use this formula:
(number of cells * 74) - 2
Following this formula, you should use 72 dp for a height of one cell, 294 dp and for a width of four cells
So if my widget is 72dp x 294dp, what size bitmaps do I need for my ldpi, mdpi and hdpi drawables?
Also, will I need any particular supports-screens settings in my manifest?
TIA,
-Frink
Update:
I've made some checkerboard patterns in various sizes and colours for each drawable- folder and tried them out. Is this density thing a bit of a red herring?
I've just done a screen-grab of my emulator running as HVGA, medium density, 320x480. The size taken up by my widget is 320x100, so I create a 320x100 bitmap in the mdpi folder as a background for my widget it looks perfect both on my emulator and LG GT540.
And for an emulator running as WVGA854, high density, 480x854. The size of my widget is 480x150. Creating a background this size and placing it in the hdpi folder displays correctly on this emulator. I have no hardware to test this on tho :-(
Update2:
I think I can explain my problem better now :-)
If I have three devices:
Device1, resolution 320x480, density ldpi
Device2, resolution 320x480, density mdpi
Device3, resolution 400x854, density mdpi
The physical size of the screens would probably all be different, but I don't think the actual sizes matter
I've worked out that Device1 and Device2 will need a background of 320x100, whereas Device3 will need 400x150
So what size background goes into the mdpi folder to display properly on Device2 and Device3?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需将 72dp x 294dp 转换为
ldpi
、mdpi
和hdpi
的实际像素大小。该过程的解释如下:http://developer.android.com/guide/practices/screens_support .html
公式为
像素 = dps * (密度/160)
,因此在您的情况下,72 dp x 294 dp 等于:更新以响应您的第二次更新:基于密度的资源旨在确保图形(大致)相同跨设备的实际尺寸。不过,就您而言,您并不关心实际大小,您关心的是背景填充它应该填充小部件的任何空间。您应该能够通过创建九个补丁图像来处理大多数背景的此问题。九个补丁将根据所需的大小进行缩放。
http://developer.android.com/guide/topics /graphics/2d-graphics.html#nine-patch
http:// /developer.android.com/guide/developing/tools/draw9patch.html
You just need to convert 72dp x 294dp into actual pixel sizes for
ldpi
,mdpi
, andhdpi
. That process is explained here:http://developer.android.com/guide/practices/screens_support.html
The formula is
pixels = dps * (density / 160)
, so in your case, 72 dp x 294 dp would equal:Update in response to your second update: Density-based resources are aimed at making sure that graphics are (roughly) the same actual size across devices. In your case, though, you don't care about the actual size, you care about the background filling up whatever space it is supposed to fill for the widget. You should be able to handle this issue for most backgrounds by created an Nine Patch image. The Nine Patch will scale according to the size required.
http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
http://developer.android.com/guide/developing/tools/draw9patch.html
Google 在此处提供了有关图标大小的良好建议:http://developer.android。 com/guide/practices/ui_guidelines/icon_design.html
我想它们也应该适用于自定义小部件。
There is good advice from Google on icon sizes here: http://developer.android.com/guide/practices/ui_guidelines/icon_design.html
I guess they should apply to custom widgets too.