gpt4 book ai didi

android - 无法解析属性 "src"中的可绘制对象

转载 作者:太空宇宙 更新时间:2023-11-03 10:55:44 25 4
gpt4 key购买 nike

我在尝试使用 drawable-mdpi 文件夹中的 xml 文件将各种图像加载到图像按钮时遇到问题。它适用于一个按钮,但不适用于另一个按钮。该代码适用于第二个图像按钮,但不适用于第一个,我收到错误,

" main.xml: Unable to resolve drawable "C:...workspace\AndroidAlarm\res\drawable-mdpi\keyEntry.xml" in attribute "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>

提前致谢!

最佳答案

资源不能包含大写字母:

    android:src="@drawable/keyEntry"

提示资源名称应该有错误:

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

关于android - 无法解析属性 "src"中的可绘制对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5108850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com