我试过重新启动 eclipse、清理、删除库等。没有任何效果!所有文件都在 res/drawable 中
这是我的主要布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView android:src="@drawable/language_line" <!-- have also tried android:background, same problem -->
android:layout_width="200dp"
android:layout_height="50dp" />
</LinearLayout>
我的 language_line.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<bitmap
android:src="@drawable/language_line_left"
android:gravity="left" />
</item>
</layer-list>
还有我的 language_line_left.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#FFFFFFFF"
android:endColor="#FF000000"
android:angle="0" />
<size
android:width="30dp"
android:height="5dp" />
</shape>
有没有人看到任何错误?
Failed to parse file C:\Programming\workspacev3\Proj\res\drawable\language_line.xml
Exception details are logged in Window > Show View > Error Log
还有这个:
org.xmlpull.v1.XmlPullParserException: Binary XML file line #6: <bitmap> requires a valid src attribute
这也仅在我尝试使用 <bitmap />
时发生,否则它工作得很好。当我 CTRL+Space
在 Eclipse 中 @drawable/language_line_left
弹出,所以它在资源中。
最佳答案
您正在尝试引用不是位图的可绘制对象。
试试这个:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/language_line_left" />
</layer-list>
关于Android XML 解析失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24601739/