无法解析属性“src”中的可绘制对象
我在尝试使用 drawable-mdpi 文件夹中的 xml 文件将各种图像加载到图像按钮时遇到问题。它适用于一个按钮,但不适用于另一个按钮。该代码适用于第二个图像按钮,但不适用于第一个图像按钮,我收到错误,
" main.xml: 无法解析可绘制对象 “C:...workspace\AndroidAlarm\res\drawable-mdpi\keyEntry.xml”中 属性“src”。
我在第一个 imageButton 中做了与第二个 imageButton 完全相同的操作。第二个按钮(工作按钮)的 xml 文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/events_pressed" /> <!-- pressed -->
<item android:drawable="@drawable/events" /> <!-- default -->
</selector>
对于不起作用的按钮,它看起来像:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/key_entry_pressed" /> <!-- pressed -->
<item android:drawable="@drawable/key_entry" /> <!-- default -->
</selector>
两者之间的唯一区别是传入的图像。所有图像都可以在drawabl-中找到mdpi 文件夹。我不明白为什么它适用于第二个图像按钮但不适用于第一个图像按钮。这两个按钮的 xml 代码如下所示:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageButton
android:id="@+id/imagebutton1"
android:src="@drawable/keyEntry"
android:background = "@android:color/transparent"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:scaleType = "fitXY"
android:layout_marginTop = "50px"
android:layout_marginLeft = "40px"
android:layout_marginRight = "20px"
android:layout_marginBottom = "50px"
android:layout_weight="1"/>
<ImageButton
android:layout_marginTop="50px"
android:layout_width="wrap_content"
android:layout_marginRight="40px"
android:id="@+id/imagebutton2"
android:layout_weight="1"
android:src="@drawable/events"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:layout_marginLeft="20px"
android:layout_marginBottom="50px"
android:scaleType="fitXY">
</ImageButton>
</LinearLayout>
提前致谢!
I'm having a problem when trying to load various images to an image button using an xml file in the drawable-mdpi folder. It worked for one button but doesn't work for the other. The code works for the second image button but not the first, I get the error,
" main.xml: Unable to resolve drawable
"C:...workspace\AndroidAlarm\res\drawable-mdpi\keyEntry.xml" in
attribute "src".
I did the exact same thing in the first imageButton that I did for the second. The xml file for the second button (working one) looks like:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/events_pressed" /> <!-- pressed -->
<item android:drawable="@drawable/events" /> <!-- default -->
</selector>
and for the one that doesn't work, it looks like:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/key_entry_pressed" /> <!-- pressed -->
<item android:drawable="@drawable/key_entry" /> <!-- default -->
</selector>
The only difference between the two is the images being passed in. All the images are found in the drawabl-mdpi folder. I can't figure out why it works for the second image button but not the first. the xml code for the two buttons looks like:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageButton
android:id="@+id/imagebutton1"
android:src="@drawable/keyEntry"
android:background = "@android:color/transparent"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:scaleType = "fitXY"
android:layout_marginTop = "50px"
android:layout_marginLeft = "40px"
android:layout_marginRight = "20px"
android:layout_marginBottom = "50px"
android:layout_weight="1"/>
<ImageButton
android:layout_marginTop="50px"
android:layout_width="wrap_content"
android:layout_marginRight="40px"
android:id="@+id/imagebutton2"
android:layout_weight="1"
android:src="@drawable/events"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:layout_marginLeft="20px"
android:layout_marginBottom="50px"
android:scaleType="fitXY">
</ImageButton>
</LinearLayout>
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
资源不能包含大写字母:
您应该在抱怨资源名称时出错:
Resources can not contain capital letters:
You should have error complaining about resource name: