本文介绍了Android部件位图尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我写一个小部件,但我不能确定作为背景,每个屏幕的分辨率/密度使用什么尺寸的位图。

I am writing a widget, but am unsure what size bitmap to use as a background for each screen resolution/density.

按照 Android开发应用程序的窗口小部件教程:

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和华电国际可绘制?

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

更新:我做了各种尺寸和颜色却有些棋盘图案为每drawable-文件夹,并试图出来。这是密度事情有点红鲱鱼?

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?

我刚刚做了一个屏幕,抓住我的模拟器上运行为HVGA,中密度,小320x480的。我的小部件所占用的大小为320x100,所以我创建了一个320x100位图在MDPI文件夹作为背景,我的小部件,它看起来既完美对我的模拟器和LG GT540。

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.

和运行的WVGA854,密度高,为480x854的仿真器。我的窗口小部件的大小是小480x150。创建一个背景这种规模和正确放置在华电国际文件夹显示在这个仿真器。我没有硬件来寿测试: - (

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:我想我最好现在就可以解释我的问题: - )

Update2:I think I can explain my problem better now :-)

如果我有三个设备:

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

我已经计算出设备1和设备2将需要320x100的背景下,而设备3需要400x150那么,什么尺寸的背景进入MDPI文件夹正确的设备2和设备3显示?

I've worked out that Device1 and Device2 will need a background of 320x100, whereas Device3 will need 400x150So what size background goes into the mdpi folder to display properly on Device2 and Device3?

推荐答案

您只需要转换72dp x 294dp到实际像素大小 LDPI MDPI 华电国际。这一过程在此说明:

You just need to convert 72dp x 294dp into actual pixel sizes for ldpi, mdpi, and hdpi. That process is explained here:

http://developer.android.com/guide/practices/screens_support.html

其计算公式为像素= DPS *(密度/ 160),所以你的情况,72 DP x 294 DP就等于:

The formula is pixels = dps * (density / 160), so in your case, 72 dp x 294 dp would equal:

  • 在LDPI(120):54 x 221像素
  • MDPI(160):72 x 294像素
  • 华电国际(240):108 x 441像素
  • 在xhdpi(320):144 x 588像素

更新响应你的第二个更新:密度为基础的资源旨在确保图形(大致)相同的实际大小跨设备。在你的情况,但是,你不关心的实际大小,你所关心的背景填充任何空间,这是为了填补小部件。你应该能够处理这个问题对于大多数的背景所创造的九修补形象。九补丁将根据所需规模的增加。

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

这篇关于Android部件位图尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 14:13