我在 res/drawable 目录中的“custom_easy_but.xml”中有一个按钮背景描述如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/but_easy_p"
android:state_pressed="true"/>
<item android:drawable="@drawable/but_easy" />
</selector>
然后我有一个名为 modeselect.xml 的布局,其中包含以下代码:
<Button
android:id="@+id/easy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="@drawable/custom_easy_but"
android:text="@string/Easy" />
然后我在名为 but_easy.png 和 but_easy_p.png 的文件中设置了一组不同大小的图像,分别位于 res/drawable-large 和 res/drawable-normal 目录中。该代码在各种手机上编译、运行和显示正确的按钮背景图像……但是如果我使用 eclipse 查看文件 modeselect.xml 并切换到“图形布局” View ,我看不到背景图像完全没有,在我看到的图形 View 下面
failed to parse file c:\blah\blah\res\drawable\custom_easy_but.xml
和
couldn't resolve resource @drawable/but_easy_p
怎么可能真机能把所有的xml都整理出来而eclipse不行呢?
最佳答案
确保您在图形编辑器中设置了正确的屏幕尺寸。如果您选择了没有资源的屏幕尺寸,您的布局将不会显示。
关于android - 图形布局不会显示我的按钮背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15026019/