Xamarin Android TableRow android:layout_span=2

526 Views Asked by At

Simplifing I have a table with 2 Rows. One Row have a TextView and the other Row has 2 textView... I need to use a android:layout_span="2" but it is not wowrkin. the resutl i have is like this

enter image description here

And my code is like this

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical">
  <LinearLayout 
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" >
    <TableLayout
          android:id="@+id/tableLayout1"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content">
      <TableRow
           android:gravity="center_horizontal"
          android:layout_width="match_parent"
          android:layout_height="wrap_content">
        <TextView
              android:layout_span="2"
              android:layout_width="300sp"
              android:gravity="center"
              android:textSize="11sp"
              android:id="@+id/Orden"
              android:textStyle="bold"
              android:text="MY PORTATIL BATERIY 9V VRef>8,7V" />
      </TableRow>
      <TableRow
           android:gravity="center_horizontal"
          android:layout_width="match_parent"
          android:layout_height="wrap_content">
        <TextView
            android:gravity="center"
            android:textSize="10sp"
            android:id="@+id/Orden"
            android:text="V Med" />
        <TextView
            android:gravity="center"
            android:textSize="10sp"
            android:id="@+id/Orden"
            android:text="Venc Batery" />
      </TableRow>
  

    </TableLayout>
  </LinearLayout>
 
</FrameLayout>

I need the Title in a Single Row. What I am missing? Thanks?

2

There are 2 best solutions below

0
On

Solved...

<TableLayout
          android:id="@+id/tableLayout1"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
          android:stretchColumns="*">

I missed to add

android:stretchColumns="*"
2
On

You can use stretchColumns="* to force the layout to use the full width of the parent:

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical">
  <LinearLayout 
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" >
    <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="*">
        <TableRow
            android:gravity="center_horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TextView
                  android:layout_span="2"
                  android:layout_width="300sp"
                  android:gravity="center"
                  android:textSize="11sp"
                  android:id="@+id/Orden"
                  android:textStyle="bold"
                  android:text="MY PORTATIL BATERIY 9V VRef>8,7V" />
      </TableRow>
      <TableRow
        android:gravity="center_horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:gravity="center"
            android:textSize="10sp"
            android:id="@+id/Orden"
            android:text="V Med" />
        <TextView
            android:gravity="center"
            android:textSize="10sp"
            android:id="@+id/Orden"
            android:text="Venc Batery" />
      </TableRow>
    </TableLayout>
  </LinearLayout> 
</FrameLayout>