无法解析属性“src”中的可绘制对象

发布于 2024-10-19 02:41:29 字数 2686 浏览 3 评论 0原文

我在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执妄 2024-10-26 02:41:29

资源不能包含大写字母:

    android:src="@drawable/keyEntry"

您应该在抱怨资源名称时出错:

    Invalid file name: must contain only [a-z0-9_.]

Resources can not contain capital letters:

    android:src="@drawable/keyEntry"

You should have error complaining about resource name:

    Invalid file name: must contain only [a-z0-9_.]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文