android table layout rowspan
Asked Answered
S

3

18

I want to build the following layout but it is not working.

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>
Sexcentenary answered 3/2, 2010 at 5:55 Comment(1)
I found this really nice tutorial on tableLayout.Terrenceterrene
I
34

I put this together really fast, try this:

alt text

<?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>
Iconography answered 3/2, 2010 at 9:20 Comment(2)
Ideally the width of the imageviews should be wrap_content, and the width of the tablelayout, 0dip. Then add a layout_weight of 1.0 to the tablelayout.Elba
Just wanted to thank Jeffrey for this, I was pulling my hair out trying to figure this out and just so everyone knows, the orientation="horizontal" is very important! Best, MikeCatechu
J
7

try out this:

<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>
Jail answered 9/11, 2011 at 3:57 Comment(0)
H
2

The output of the below code

enter ima,ge description here

By Default the android doesn't have any attribute called rowspan but the below code works fine and created the row span.

<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>
Hugibert answered 22/8, 2018 at 13:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.