Android:一次不超过 1 9 个补丁图像?
我在处理九个补丁图像 ( **.9.png ) 时遇到问题。我有一个小部件布局,想使用九个补丁图像作为小部件的背景。这是我的background.xml,
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/appwidget_bg" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/appwidget_bg" />
<item android:state_focused="true" android:drawable="@drawable/appwidget_bg" />
<item android:state_focused="false" android:drawable="@drawable/appwidget_bg" />
</selector>
drawbales 名称是“appwidget_bg.9.png”。这东西工作得很好。但我想对聚焦和按下状态使用不同的图像。
所以我让它看起来像这样:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/appwidget_bg_pressed" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/appwidget_bg_pressed" />
<item android:state_focused="true" android:drawable="@drawable/appwidget_bg_pressed" />
<item android:state_focused="false" android:drawable="@drawable/appwidget_bg" />
</selector>
问题:一旦添加额外的可绘制“appwidget_bg_pressed.9.png”,我就会收到以下错误消息:
.../res/drawable/widget_bg.xml:21: ERROR 错误:找不到与给定名称匹配的资源(在“drawable”处,值为“@drawable/appwidget_bg”)。
.../AndroidManifest.xml:6:错误错误:找不到与给定名称匹配的资源(在“icon”处,值为“@drawable/icon”)。
看来我只能将九个补丁可绘制对象添加到可绘制对象文件夹中。这是为什么?
I am having problems with nine patch images ( **.9.png ). I have a widget layout and would like to use nine patch images for the widget's backgroud. Here is my background.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/appwidget_bg" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/appwidget_bg" />
<item android:state_focused="true" android:drawable="@drawable/appwidget_bg" />
<item android:state_focused="false" android:drawable="@drawable/appwidget_bg" />
</selector>
The drawbales name is "appwidget_bg.9.png". This stuff works fine. But I would like to use different images for the focused and pressed states.
So I make it look like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/appwidget_bg_pressed" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/appwidget_bg_pressed" />
<item android:state_focused="true" android:drawable="@drawable/appwidget_bg_pressed" />
<item android:state_focused="false" android:drawable="@drawable/appwidget_bg" />
</selector>
The problem: As soon as I add the additional drawable "appwidget_bg_pressed.9.png" I get the following error message:
.../res/drawable/widget_bg.xml:21: ERROR Error: No resource found that matches the given name (at 'drawable' with value '@drawable/appwidget_bg').
.../AndroidManifest.xml:6: ERROR Error: No resource found that matches the given name (at 'icon' with value '@drawable/icon').
It seems like I can only add one nine patch drawable to the drawables folder. Why is that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定它们已导入到您的drawables文件夹中吗?该错误表明未找到文件。您当然可以拥有多个 9 补丁图像。似乎找到了 appwidget_bg_pressed.9.png,但只看到了 appwidget_bg.9.png 或 icon.png
Are you certain they've been imported into your drawables folder? That error is saying it's not found the files. You can certainly have multiple 9-patch images. Seems like it's found appwidget_bg_pressed.9.png, but isn't seeing just appwidget_bg.9.png or icon.png
这是一个老问题,但我面临着同样的问题,我想通了并解决了我的问题。
问题出在 9-patch 可绘制对象上;他们的一侧有补丁,而不是两侧。因为我不希望我的可绘制对象垂直拉伸,但似乎我无法通过一侧修补来做到这一点。
我希望它能帮助其他人。
This is an old question, but I was facing same problem and I figured it out and solved my problem.
The problem was with 9-patch drawables; they had patches on one side instead of two. because I didn't want my drawable to stretch vertically but it seems that I can't do it with one side patching.
I hope it'll help others.