如何为 1x1 Android 小部件创建清晰的背景图像? [英] How to create crisp background image for 1x1 Android widget?

查看:25
本文介绍了如何为 1x1 Android 小部件创建清晰的背景图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 1x1 小部件,无论我尝试什么,我都无法让背景图像看起来又漂亮又清晰.我已经阅读了几乎所有我能找到的资源,但我仍然无法获胜.

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. I've read just about any resource I can find, yet I still can't win.

我正在为 HTC Desire/Nexus 1 设计,希望有人告诉我在 Photoshop 中创建背景时,使用的 dpi/高度/宽度(当前使用 72/100/80).一旦我首先在我的测试设备上让它看起来不错,我会担心其他设备的分辨率.

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). I'll worry about other devices resolutions once I can get it looking nice on my test device first.

另外,如果有什么特别之处,我需要放入 @layout/main.xml 和 Widget_Provider.xml 文件.我根本找不到任何 1x1 小工具的示例,所以有以下内容:

Also, if there's anything special I need to be putting in the @layout/main.xml and Widget_Provider.xml files. I simply can't find any examples for 1x1 gadgets, so have the following:

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"
/>

任何帮助将不胜感激.

推荐答案

你可能想看看 Google 的 支持多种屏幕尺寸 文档.基本上这里发生的是 Android 设备上的屏幕具有不同的像素密度.这些分为低、中、高(ldpi、mdpi、hdpi).如果资产不足以容纳更大密度的屏幕,则会将其放大到适当的大小 - 这可能是您正在发生的事情.

You may want to have a look at Google's Supporting Multiple Screen Sizes document. Basically what is happening here is that the screens on Android devices have different pixel densities. These are categorized as low, medium, high (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.

Nexus One 的 DPI 约为 250,属于 hdpi 类.使用 (细胞数 * 74) - 2 的谷歌公式来计算 1x1 小部件的 dp 将使小部件尺寸为 72x72 dp.

The Nexus One has a DPI somewhere around 250 which puts it into the hdpi class. Using the google formula of (number of cells * 74) - 2 to calculate dp for your 1x1 widget would make the widget dimensions 72x72 dp.

dp到像素的转换为:

pixels = dp * (density / 160)

因此,对于 72x72 dp 的图像,基于密度的相应图像尺寸将是:

So for a 72x72 dp image, the corresponding image sizes based on density would be:

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.

这篇关于如何为 1x1 Android 小部件创建清晰的背景图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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