老黑牛 2016-03-13 01:30 采纳率: 33.3%
浏览 1534
已采纳

关于android listView子项的问题

初学Android listView,在子项list_item.xmls中的代码如下:

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

    <LinearLayout
        android:id="@+id/left_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left" >

        <TextView
            android:id="@+id/left_text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/right_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right" >

        <TextView
            android:id="@+id/right_text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center" />
    </LinearLayout>

</LinearLayout>

这样的话整个程序都能运行,如果将最外层的

 <LinearLayout></LinearLayout>

改成

 <RelativeLayout></RelativeLayout>

,程序就会崩溃。请问各位,难道在listView的子项中,最外层的布局必须要用LinearLayout吗?

  • 写回答

3条回答

  • 103style 2016-03-18 00:30
    关注

    com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup 类型转换出错 MockView 不是一个ViewGroup

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?