如何为 1x1 Android 小部件创建清晰的背景图像?
我正在创建一个 1x1 小部件,无论我尝试什么,我都无法让背景图像看起来漂亮且清晰。我已经阅读了几乎所有我能找到的资源,但我仍然无法获胜。
我正在为 HTC Desire/Nexus 1 进行设计,希望有人告诉我在 Photoshop 中创建背景时要使用什么 dpi/高度/宽度(当前使用 72/100/80)。一旦我能首先在我的测试设备上看起来不错,我就会担心其他设备的分辨率。
另外,如果有什么特别的,我需要放入 @layout/main.xml 和 Widget_Provider.xml 文件。我根本找不到 1x1 小工具的任何示例,因此有以下内容:
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
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="72dip"
android:minHeight="72dip"
android:updatePeriodMillis="6000000"
android:initialLayout="@layout/main"
/>
任何帮助将不胜感激。
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.
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.
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
<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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要查看 Google 的支持多种屏幕尺寸文档。基本上,这里发生的是 Android 设备上的屏幕具有不同的像素密度。这些被分类为低、中、高(ldpi、mdpi、hdpi)。如果某个资源对于更大密度的屏幕来说不够大,它就会被放大到适当的尺寸 - 这可能就是您正在发生的情况。
Nexus One 的 DPI 约为 250,属于 hdpi 级别。使用谷歌公式(单元格数量 * 74)- 2 计算 1x1 小部件的 dp 将使小部件尺寸为 72x72 dp。
从 dp 到像素的转换为:
因此,对于 72x72 dp 图像,基于密度的相应图像尺寸为:
使用这些公式创建您的资源,您应该获得清晰的图像。
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.
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.
The conversion from dp to pixels is:
So for a 72x72 dp image, the corresponding image sizes based on density would be:
Use these formulas to create your assets and you should get crisp images.