【问题标题】:Listview error: parsing xml not well-formed (invalid token)Listview 错误:解析 xml 格式不正确(无效令牌)
【发布时间】:2014-07-14 02:55:15
【问题描述】:

尝试了我在网上可以阅读的所有内容,但无济于事。在此 fragment_main.xml 代码上出现上述错误。我想用线性布局中的一些文本创建一个简单的列表视图。请指出错误。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TextView
android:id="@+id/selection"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff0000cc"
android:textStyle="bold“ />
</TextView>

<ListView android:id="@android:id:listView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false">    
</ListView>

<TextView android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Empty set"/>
</TextView>

</LinearLayout>

【问题讨论】:

    标签: android xml


    【解决方案1】:

    改变这个

     android:textStyle="bold“ />
     </TextView>
    

     android:textStyle="bold“ /> // this /> indicates the end of tag
    

    改变这个

     android:textStyle="bold“ 
    

    android:textStyle="bold" // note the ""  
    

    其他文本视图也是如此

    android:text="@string/Empty set"/>
    </TextView>
    

    改成

    android:text="@string/Empty set"/>
    

    终于

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <TextView
            android:id="@+id/selection"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#ff0000cc"
            android:textStyle="bold" />
    
        <ListView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:drawSelectorOnTop="false" >
        </ListView>
    
        <TextView
            android:id="@android:id/empty"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/Empty set" />
    
    </LinearLayout>
    

    注意:fill_parent(在 API 级别 8 中重命名为 match_parent)告诉您的视图变得与其父视图组允许的一样大。

    所以使用match_parent 而不是fill_parent

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多