zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

Android - Layout时发生'Unfortunately xxx has stopped'

Android &# 39 has 发生 xxx layout
2023-09-27 14:28:06 时间

概述

  我在进行LinearLayout和TableLayout的嵌套布局的时候,发生题的错误.如下布局xml代码:

 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     android:layout_width="fill_parent"
 3     android:layout_height="fill_parent"
 4     android:orientation="vertical" >
 5 
 6     <LinearLayout
 7         android:layout_width="fill_parent"
 8         android:layout_height="fill_parent"
 9         android:layout_weight="1"
10         android:orientation="horizontal" >
11 
12         <TextView
13             android:layout_width="wrap_content"
14             android:layout_height="fill_parent"
15             android:layout_weight="1"
16             android:background="#996699"
17             android:gravity="center"
18             android:text="one" />
19 
20         <TextView
21             android:layout_width="wrap_content"
22             android:layout_height="fill_parent"
23             android:layout_weight="1"
24             android:background="#FFFF99"
25             android:gravity="center"
26             android:text="two" />
27 
28         <TextView
29             android:layout_width="wrap_content"
30             android:layout_height="fill_parent"
31             android:layout_weight="1"
32             android:background="#CC9966"
33             android:gravity="center"
34             android:text="three" />
35 
36         <TextView
37             android:layout_width="wrap_content"
38             android:layout_height="fill_parent"
39             android:layout_weight="1"
40             android:background="#CCCC99"
41             android:gravity="center"
42             android:text="four" />
43     </LinearLayout>
44 
45     <LinearLayout
46         android:layout_width="fill_parent"
47         android:layout_height="fill_parent"
48         android:layout_weight="1"
49         android:orientation="vertical" >
50 
51         <TableLayout>
52 
53             <TableRow>
54 
55                 <TextView
56                     android:layout_width="fill_parent"
57                     android:layout_height="wrap_content"
58                     android:layout_weight="1"
59                     android:background="#993333"
60                     android:gravity="center"
61                     android:text="five" />
62 
63                 <TextView
64                     android:layout_width="fill_parent"
65                     android:layout_height="wrap_content"
66                     android:layout_weight="1"
67                     android:background="#CCCCCC"
68                     android:gravity="center"
69                     android:text="six" />
70             </TableRow>
71 
72             <TableRow>
73 
74                 <TextView
75                     android:layout_width="fill_parent"
76                     android:layout_height="wrap_content"
77                     android:layout_weight="1"
78                     android:background="#FFFF99"
79                     android:gravity="center"
80                     android:text="seven" />
81             </TableRow>
82         </TableLayout>
83     </LinearLayout>
84 
85 </LinearLayout>
View Code

   其中,应该在第51行中,TableLayout加上'layout_width'和'layout_height'属性.即可.如下(第46/47行):

 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     android:layout_width="fill_parent"
 3     android:layout_height="fill_parent"
 4     android:orientation="vertical" >
 5 
 6     <LinearLayout
 7         android:layout_width="fill_parent"
 8         android:layout_height="fill_parent"
 9         android:layout_weight="1"
10         android:orientation="horizontal" >
11 
12         <TextView
13             android:layout_width="wrap_content"
14             android:layout_height="fill_parent"
15             android:layout_weight="1"
16             android:background="#996699"
17             android:gravity="center"
18             android:text="one" />
19 
20         <TextView
21             android:layout_width="wrap_content"
22             android:layout_height="fill_parent"
23             android:layout_weight="1"
24             android:background="#FFFF99"
25             android:gravity="center"
26             android:text="two" />
27 
28         <TextView
29             android:layout_width="wrap_content"
30             android:layout_height="fill_parent"
31             android:layout_weight="1"
32             android:background="#CC9966"
33             android:gravity="center"
34             android:text="three" />
35 
36         <TextView
37             android:layout_width="wrap_content"
38             android:layout_height="fill_parent"
39             android:layout_weight="1"
40             android:background="#CCCC99"
41             android:gravity="center"
42             android:text="four" />
43     </LinearLayout>
44 
45     <LinearLayout
46         android:layout_width="fill_parent"
47         android:layout_height="fill_parent"
48         android:layout_weight="1"
49         android:orientation="vertical" >
50 
51         <TableLayout
52             android:layout_width="fill_parent"
53             android:layout_height="fill_parent" >
54 
55             <TableRow>
56 
57                 <TextView
58                     android:layout_width="fill_parent"
59                     android:layout_height="wrap_content"
60                     android:layout_weight="1"
61                     android:background="#993333"
62                     android:gravity="center"
63                     android:text="five" />
64 
65                 <TextView
66                     android:layout_width="fill_parent"
67                     android:layout_height="wrap_content"
68                     android:layout_weight="1"
69                     android:background="#CCCCCC"
70                     android:gravity="center"
71                     android:text="six" />
72             </TableRow>
73 
74             <TableRow>
75 
76                 <TextView
77                     android:layout_width="fill_parent"
78                     android:layout_height="wrap_content"
79                     android:layout_weight="1"
80                     android:background="#FFFF99"
81                     android:gravity="center"
82                     android:text="seven" />
83             </TableRow>
84         </TableLayout>
85     </LinearLayout>
86 
87 </LinearLayout>
View Code