【问题标题】:android table layout rowspanandroid表格布局rowspan
【发布时间】:2011-01-12 11:55:36
【问题描述】:

我想构建以下布局,但它不起作用。

alt text http://toms-toy.de/rowspan.gif

<LinearLayout android:orientation="horizontal"...>
  <ImageView ...></ImageView>
        <TableLayout ...>
                        <TableRow..>
                              <ImageView ...></ImageView>
                              <ImageView ...></ImageView>
                              <ImageView ...></ImageView>
                        </TableRow>
                         <TableRow..>
                              <ImageView ...></ImageView>
                              <ImageView ...></ImageView>
                              <ImageView ...></ImageView>
                        </TableRow>
       </TableLayout>
  <ImageView ...></ImageView>
</LinearLayout>

【问题讨论】:

标签: android tablelayout html-table


【解决方案1】:

以下代码的输出

默认情况下,android 没有任何名为 rowspan 的属性,但下面的代码可以正常工作并创建了行跨度。

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
    <TableRow>
        <TextView
            android:text="Hello"
            android:textSize="30dp"
            />
        <TextView
            android:text="Hello World"
            android:textSize="30dp"
            android:background="@drawable/border"

            />
        <Button android:text="Click me"
            android:textSize="30dp"/>

    </TableRow>

    <TableRow>
        <TextView
            android:text="Hello"
            android:textSize="30dp"
            />
           <Button android:text="Click"
            android:textSize="30dp"
               android:layout_column="2"/>

    </TableRow>
    <TableRow>
        <TextView
            android:text="Hello"
            android:textSize="30dp"
            />
        <TextView
            android:text="Hello"
            android:textSize="30dp"
            />
        <Button android:text="Click me"
            android:textSize="30dp"/>

    </TableRow>
    <TableRow>
        <TableLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_span="2">
            <TableRow>
                <Button android:text="1"/>
                <Button android:text="2"/>
            </TableRow>
            <TableRow>
                <Button android:text="3"/>
                <Button android:text="4"/>
            </TableRow>

        </TableLayout>
        <Button
            android:layout_height="match_parent"
            android:layout_width="wrap_content"
            android:text="Enter"
            android:background="#ff0099"/>
    </TableRow>
</TableLayout>

【讨论】:

    【解决方案2】:

    试试这个:

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TableRow>
            <TextView android:text="1-2, 1;\t" android:layout_gravity="center" />
            <TableLayout>
                <TableRow>
                    <TextView android:text="1, 2;\t" android:layout_gravity="center" />
                </TableRow>
                <TableRow>
                    <TextView android:text="2, 2;\t" android:layout_gravity="center" />
                </TableRow>
            </TableLayout>
        </TableRow>
    </TableLayout>
    

    【讨论】:

      【解决方案3】:

      我很快就把它放在一起,试试这个:

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="horizontal" 
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent">
          <ImageView android:layout_width="50dip" android:layout_height="100dip" android:background="#cc0000"/>
          <TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
              <TableRow>
                  <ImageView android:layout_width="50dip" android:layout_height="50dip" android:background="#aaaa00"/>
                  <ImageView android:layout_width="50dip" android:layout_height="50dip" android:background="#00aa00"/>
                  <ImageView android:layout_width="50dip" android:layout_height="50dip" android:background="#aaaa00"/>
              </TableRow>
              <TableRow>
                  <ImageView android:layout_width="50dip" android:layout_height="50dip" android:background="#00aa00"/>
                  <ImageView android:layout_width="50dip" android:layout_height="50dip" android:background="#aaaa00"/>
                  <ImageView android:layout_width="50dip" android:layout_height="50dip" android:background="#00aa00"/>
              </TableRow>
          </TableLayout>
          <ImageView android:layout_width="50dip" android:layout_height="100dip" android:background="#cc0000"/>
      </LinearLayout>
      

      【讨论】:

      • 理想情况下,imageviews 的宽度应该是 wrap_content,tablelayout 的宽度应该是 0dip。然后给tablelayout添加一个1.0的layout_weight。
      • 只是想为此感谢 Jeffrey,我正在努力解决这个问题,所以大家都知道,orientation="horizo​​ntal" 非常重要!最好的,迈克
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-25
      • 1970-01-01
      • 2017-04-15
      • 2014-05-13
      相关资源
      最近更新 更多