简体   繁体   English

在表格行中插入表格行

[英]Inserting a table row inside a table row

I want to insert two table rows inside a table row vertically. 我想在一个表行中垂直插入两个表行。 this is being done but the rows are being added horizontally instead of vertically. 这已经完成,但是行是水平添加的,而不是垂直添加的。 How to add vertical rows.. Following is my xml. 如何添加垂直行。以下是我的xml。

                <TableLayout 
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/TableLAyout1"
                >
                    <TableRow 
                        android:layout_width="fill_parent"

                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                    >
                        <TableRow
                        android:layout_column="0"
                        android:layout_width="fill_parent"
                        android:background="@drawable/eventbar"
                         android:layout_height="wrap_content"
                         android:id="@+id/TableRow1" >
                        <TextView 
                            android:gravity="center_vertical"
                            android:layout_width="wrap_content"
                            android:text="Calendar for 14 August 2011"
                            android:layout_height="wrap_content"
                            android:textColor="@drawable/white"
                            android:layout_marginLeft="10dp"
                        />
                        </TableRow>
                        <TableRow 
                        android:layout_column="0"
                            android:layout_below="@+id/TableRow1"
                           android:layout_width="fill_parent"
                           android:background="@drawable/bgrow"
                           android:layout_height="wrap_content">
                                <ListView 
                                    android:layout_height="wrap_content"
                                    android:layout_width="fill_parent"
                                    android:id="@+id/ListView2" >
                                </ListView>
                        </TableRow>
                    </TableRow>

                </TableLayout>

Can anyone help me how to this? 谁能帮我怎么做?

I think you misunderstood how TableLayout works. 我认为您误解了TableLayout工作原理。 If you read up in the tutorial you will see, that TableLayout works similarly to HTML tables, meaning that TableRow actually defines a row , not a column and is not even intended to do otherwise. 如果您在本教程中进行了阅读 ,将会看到TableLayout与HTML表的工作方式相似,这意味着TableRow实际上定义了row而不是column,并且甚至不打算这样做。 The columns are created automatically based on the views you add to the rows. 列是根据您添加到行中的视图自动创建的。

Thus, if you want to have two rows with two TextViews each, you just add two TableRow s to your TableLayout , and insert two TextView s into each of them. 因此,如果要具有两行且每个行都有两个TextViews ,则只需将两个TableRow添加到TableLayout ,然后将两个TextView插入到每个行中。

I think what you should do is have tableLayout inside the main table row and in the inner tablelayout you can have 2 rows and have the onclick event on the main tablerow. 我认为您应该做的是在主表行内有tableLayout,在内部表布局中可以有2行,并且在主表行上具有onclick事件。 Even I am trying something like this, will update if it works. 即使我正在尝试类似的方法,如果可以的话也会进行更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM