Android XML无法解析

时间:2014-07-07 00:53:07

标签: android android-layout android-xml

我尝试重新启动日食,清理,拿走图书馆等。没有任何作用!所有文件都驻留在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 />时才会发生,否则它会正常工作。当我在Eclipse中CTRL+Space弹出@drawable/language_line_left时,它就在资源中。

1 个答案:

答案 0 :(得分:1)

您正在尝试引用不是位图的drawable。

试试这个:

<?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>