简体   繁体   English

如何为1x1 Android小部件创建清晰的背景图像?

[英]How to create crisp background image for 1x1 Android widget?

I'm creating an a 1x1 widget, and no matter what I try, I just can't get the background image looking nice and crisp. 我正在创建一个1x1的小部件,无论我尝试什么,我都无法使背景图像看起来清晰明快。 I've read just about any resource I can find, yet I still can't win. 我已经读了几乎所有可以找到的资源,但我仍然无法取胜。

I'm designing for the HTC Desire/Nexus 1, and would love someone to tell me when creating the background in Photoshop, what dpi/height/width to use (currently using 72/100/80). 我正在为HTC Desire / Nexus 1设计,并希望有人告诉我在Photoshop中创建背景时要使用的dpi /高度/宽度(当前使用72/100/80)。 I'll worry about other devices resolutions once I can get it looking nice on my test device first. 一旦让它在我的测试设备上看起来不错,我就会担心其他设备的分辨率。

Also, if there's anything special I need to be putting in the @layout/main.xml and Widget_Provider.xml files. 另外,如果有什么特别的地方,我需要放入@ layout / main.xml和Widget_Provider.xml文件。 I simply can't find any examples for 1x1 gadgets, so have the following: 我根本找不到1x1小工具的任何示例,因此具有以下内容:

main.xml main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget"
android:layout_width="fill_parent"
android:orientation="vertical"
android:background="@drawable/background" 
android:layout_gravity="center" 
android:layout_height="wrap_content">

Widget_Provider.xml Widget_Provider.xml

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="72dip"
android:minHeight="72dip"
android:updatePeriodMillis="6000000"
android:initialLayout="@layout/main"
/>

Any help would be greatly appreciated. 任何帮助将不胜感激。

You may want to have a look at Google's Supporting Multiple Screen Sizes document. 您可能需要查看Google的支持多种屏幕尺寸文档。 Basically what is happening here is that the screens on Android devices have different pixel densities. 基本上,这里发生的是Android设备上的屏幕具有不同的像素密度。 These are categorized as low, medium, high (ldpi, mdpi, hdpi). 这些分类为低,中,高(ldpi,mdpi,hdpi)。 If an asset isn't large enough for a larger density screen, it is blown up to the proper size - this is probably what is happening to you. 如果资产不足以容纳更大密度的屏幕,则会将其放大至适当的尺寸-这可能是您正在发生的事情。

The Nexus One has a DPI somewhere around 250 which puts it into the hdpi class. Nexus One的DPI大约在250左右,这使其属于hdpi类。 Using the google formula of (number of cells * 74) - 2 to calculate dp for your 1x1 widget would make the widget dimensions 72x72 dp. 使用(单元数* 74)-2的google公式来计算1x1小部件的dp会使小部件尺寸为72x72 dp。

The conversion from dp to pixels is: 从dp到像素的转换是:

pixels = dp * (density / 160)

So for a 72x72 dp image, the corresponding image sizes based on density would be: 因此,对于72x72 dp图像,基于密度的相应图像尺寸为:

ldpi  (120 DPI) = 72 * (120 / 160) == 54 x 54 pixels
mdpi  (160 DPI) = 72 * (160 / 160) == 72 x 72 pixels
hdpi  (240 DPI) = 72 * (240 / 160) == 108 x 108 pixels
xhdpi (320 DPI) = 72 * (320 / 160) == 144 x 144 pixels

Use these formulas to create your assets and you should get crisp images. 使用这些公式创建资产,您将获得清晰的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM