简体   繁体   中英

How do I make my TableRow cells all the same height?

I am using the following XML for a TableLayout in Android.

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="#FFFFFF">
    <TableRow>
    <TextView
        android:id="@+id/SDevRow2"
        android:layout_width="60dp"
        android:layout_height="wrap_content"
        android:text="-2.50"
        android:background="@drawable/columncellbg"
        />
    <TextView
        android:id="@+id/vitalText1"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="100"
        android:background="@drawable/columncellwhite"
        />
    <TextView
        android:id="@+id/Yellow1"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:text=""
        android:background="@drawable/columncellyellow"
        />
    <TextView
        android:id="@+id/Red1"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:text=""
        android:background="@drawable/columncellred"
        />
    <TextView
        android:id="@+id/Action1"
        android:layout_width="60dp"
        android:layout_height="wrap_content"
        android:text="Action"
        android:background="@drawable/columncellwhite"
        />
    </TableRow>
    <TableRow
    android:layout_width="match_parent"
    android:layout_height="20dp"
    >
    <TextView
    android:id="@+id/SDevRow2"
    android:layout_width="60dp"
    android:layout_height="20dp"
    android:text="Low"
    android:background="@drawable/columncellbg"
    />
    <TextView
    android:id="@+id/vitalText1"
    android:layout_width="100dp"
    android:layout_height="20dp"
    android:text="100"
    android:background="@drawable/columncellwhite"
    />
    <CheckBox
    android:id="@+id/Yellow17"
    android:layout_width="50dp"
    android:layout_height="20dp"
    android:text=""
    android:textColor="@color/Black"
    android:background="@drawable/columncellyellow"
    android:button="@drawable/customcheckbox"
    />
    <TextView
    android:id="@+id/Red1"
    android:layout_width="50dp"
    android:layout_height="20dp"
    android:text=""
    android:background="@drawable/columncellred"
    />
   <TextView
    android:id="@+id/Action1"
    android:layout_width="60dp"
    android:layout_height="20dp"
    android:text="Action"
    android:background="@drawable/columncellwhite"
    />
    </TableRow>
    </TableLayout>

The result looks like this: 布置结果

How do I get rid of the gap between the two table rows? I tried expanding the cell heights of the TextView cells, but the gap persisted. I want to force everything to be the same height.

Ok, I fixed the problem by wrapping the checkbox in a LinearLayout. That's weird and I don't know why it's required, so if anyone can tell me why that would be awesome.

<LinearLayout
    android:layout_width="50dp"
    android:layout_height="20dp"
    android:text=""
    android:textColor="@color/Black"
    android:background="@drawable/columncellyellow"
    >
    <CheckBox
        android:id="@+id/Yellow17"
        android:button="@drawable/customcheckbox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"/>
    </LinearLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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