Android表布局与按钮强制关闭-没有错误在eclipse -为什么



我创建了一个新项目,我唯一改变的是activity_main.xml文件。我将RelativeLayout改为LinearLayout,并设置android:orientation="vertical",然后在这个布局中添加以下组件:

<LinearLayout android:orientation="horizontal"
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent">
    <Button android:id="@+id/b00"
        android:text="X"></Button>
    <Button android:id="@+id/b01"
        android:text="X"></Button>
    <Button android:id="@+id/b02"
        android:text="X"></Button>
</LinearLayout>
<LinearLayout android:orientation="horizontal"
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent">
    <Button android:id="@+id/b10"
        android:text="X"></Button>
    <Button android:id="@+id/b11"
        android:text="X"></Button>
    <Button android:id="@+id/b12"
        android:text="X"></Button>
</LinearLayout>
<LinearLayout android:orientation="horizontal"
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent">
    <Button android:id="@+id/b20"
        android:text="X"></Button>
    <Button android:id="@+id/b21"
        android:text="X"></Button>
    <Button android:id="@+id/b22"
        android:text="X"></Button>
</LinearLayout>

在测试这个应用程序时,什么也没有显示(没有按钮或任何东西)。它像这样运行了几秒钟,然后就关闭了。请帮助!

编辑:这是logcat说的…

03-10 18:10:02.190: I/dalvikvm(25796): threadid=4: reacting to signal 3
03-10 18:10:02.200: I/dalvikvm(25796): Wrote stack traces to '/data/anr/traces.txt'
03-10 18:10:06.720: I/Process(25796): Sending signal. PID: 25796 SIG: 9

I can't find/data/anr/traces.txt

您需要将android:layout_widthandroid:layout_height属性添加到布局XML实体中。例如:

改变:

<Button
    android:id="@+id/b00"
    android:text="X">
</Button>

:

<Button
    android:id="@+id/b00"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="X">
</Button>

最新更新