1

我有一个在异步任务中创建的 listView,在我更改布局之前,listView 运行良好,布局有什么问题?我确实在布局中添加了更多文本视图。要在列表项中有多个 textView,我需要做些什么特别的事情吗?这是我当前的布局,它使应用程序崩溃,

     <?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_margin="10dip"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:background="@drawable/comment_box_bg">


<RelativeLayout android:id="@+id/listCommentBoxHeader"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/comment_box_header">

    <TextView 
    android:id="@+id/listNumber"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:textSize="16sp"
        android:layout_alignParentLeft="true"
        android:textColor="#FFFFFF"
        android:textStyle="bold" >
</TextView>
<TextView 
    android:id="@+id/listPostedBy"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:textSize="16sp"
        android:layout_alignParentRight="true"
        android:textColor="#FFFFFF"
        android:textStyle="bold" >
</TextView>

</RelativeLayout>

<TextView 
    android:id="@+id/listComment"
    android:layout_below="@id/listCommentBoxHeader"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dip"
        android:textSize="16sp"
        android:background="@drawable/comment_bg"
        android:textColor="#000000"
        android:textStyle="bold" >
</TextView>
<button android:id="@+id/listNumberButton"
    android:layout_margin="5dip"
    android:padding="5dip"
    android:textColor="#FFFFFF"
    android:textStyle="bold"
    android:textSize="16sp"
    android:background="@drawable/dashboard_post"
    android:layout_alignParentLeft="true"/>

    <button android:id="@+id/listUsernameButton"
    android:layout_margin="5dip"
    android:padding="5dip"
    android:textColor="#FFFFFF"
    android:textStyle="bold"
    android:textSize="16sp"
    android:background="@drawable/dashboard_post"
    android:layout_alignParentRight="true"/>

</RelativeLayout>

这是logCat,

 07-09 20:15:07.568: D/AndroidRuntime(21589): Shutting down VM
07-09 20:15:07.568: W/dalvikvm(21589): threadid=1: thread exiting with uncaught exception (group=0x40ac9228)
07-09 20:15:07.588: E/AndroidRuntime(21589): FATAL EXCEPTION: main
07-09 20:15:07.588: E/AndroidRuntime(21589): java.lang.RuntimeException: Binary XML file line #49: You must supply a layout_width attribute.
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:491)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:5326)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:5447)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.RelativeLayout$LayoutParams.<init>(RelativeLayout.java:1064)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:933)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:69)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:741)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:371)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.AbsListView.obtainView(AbsListView.java:2046)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.ListView.measureHeightOfChildren(ListView.java:1292)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.ListView.onMeasure(ListView.java:1155)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.View.measure(View.java:13011)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.View.measure(View.java:13011)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.RelativeLayout.measureChild(RelativeLayout.java:579)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:392)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.View.measure(View.java:13011)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1017)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:555)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.View.measure(View.java:13011)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.View.measure(View.java:13011)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:812)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.View.measure(View.java:13011)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.View.measure(View.java:13011)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at com.navdrawer.SimpleSideDrawer.onMeasure(SimpleSideDrawer.java:443)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.View.measure(View.java:13011)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2162)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.View.measure(View.java:13011)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1091)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2505)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.os.Looper.loop(Looper.java:154)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at android.app.ActivityThread.main(ActivityThread.java:4945)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at java.lang.reflect.Method.invokeNative(Native Method)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at java.lang.reflect.Method.invoke(Method.java:511)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-09 20:15:07.588: E/AndroidRuntime(21589):    at dalvik.system.NativeStart.main(Native Method)
4

2 回答 2

0

在您的 XML 文件中替换<button<Button(找到两次),您应该一切顺利。如果项目仍然无法正常工作,请清理项目。

XML 标记对键敏感。这是对Button类的引用:http: //developer.android.com/reference/android/widget/Button.html

于 2013-07-10T00:04:21.543 回答
0

好像您从其他地方获得了此代码。请在测试前验证您是否是可绘制资源。如果不是,请从文件中删除它们。(android:background="@drawable/comment_box_bg")

他们似乎有很多自定义背景。

使用这个 xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_margin="10dip"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:background="@drawable/comment_box_bg">


<RelativeLayout android:id="@+id/listCommentBoxHeader"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/comment_box_header">

    <TextView 
    android:id="@+id/listNumber"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:textSize="16sp"
        android:layout_alignParentLeft="true"
        android:textColor="#FFFFFF"
        android:textStyle="bold" >
</TextView>
<TextView 
    android:id="@+id/listPostedBy"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:textSize="16sp"
        android:layout_alignParentRight="true"
        android:textColor="#FFFFFF"
        android:textStyle="bold" >
</TextView>

</RelativeLayout>

<TextView 
    android:id="@+id/listComment"
    android:layout_below="@id/listCommentBoxHeader"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dip"
        android:textSize="16sp"
        android:background="@drawable/comment_bg"
        android:textColor="#000000"
        android:textStyle="bold" >
</TextView>


<Button android:id="@+id/listNumberButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dip"
        android:padding="5dip"
        android:textColor="#FFFFFF"
        android:textStyle="bold"
        android:textSize="16sp"
        android:background="@drawable/dashboard_post"
        android:layout_alignParentLeft="true"/>

   <Button android:id="@+id/listUsernameButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dip"
        android:padding="5dip"
        android:textColor="#FFFFFF"
        android:textStyle="bold"
        android:textSize="16sp"
        android:background="@drawable/dashboard_post"
        android:layout_alignParentRight="true"/>

</RelativeLayout>
于 2013-07-10T00:31:49.127 回答