【发布时间】:2012-10-30 20:33:30
【问题描述】:
我制作了一个程序,它在窗口顶部(标题栏正下方)有一个视图。 根据程序中发生的情况,视图的颜色会发生变化。
这很好用。
现在我的问题是:我想要里面有 2 个文本视图,彼此相邻。所以可能:View、Tablelayout、tablerow、textview、textview、tablerow end、tablelayout end、view end。
但这似乎不起作用。它给了我错误“Java.lang.RuntimeException: Unable to start activity ComponentInfo”和“View can't be cast to viewgroup”。
我在 java 代码中没有任何地方触及 xml 代码中的任何新视图,唯一触及 XML 的 java 是 TopView = (View)findViewById(R.id.TopView); 和 TopView.setBackgroundColor(Color.GREEN ); Topview 是外部视图,并且内部没有任何东西可以完美运行.
这是 XML 代码
...
<View
android:id="@+id/TopView"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:background="#8E8E8E" >
<TableLayout
android:id="@+id/tableTrolo"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="@+id/TableRow000"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:gravity="left"
android:orientation="vertical" >
<TextView
android:id="@+id/lbl1"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Vare :"
android:textSize="22dp" />
<TextView
android:id="@+id/lbl2"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:text="du grim" />
</TableRow>
</TableLayout>
</View>
...
【问题讨论】: