mardi 21 juin 2016

Aligning columns headings on custom listview checkboxes

I'm using a tablelayout where each row has a number of checkboxes, and am using a custom adapter. The columns do expand evenly across the screen. On the parent layout I also have a series of "check/uncheck all" type checkboxes and they line up perfectly with the listview checkboxes. My issue is that I can't get column headings for the checkboxes to line up with the columns. They have a creep, either too much or too little, let alone working across both phone and tablet devices. My suspicion is that the problem may be caused by the text associated with the leftmost checkboxs, the only ones that have any text associated with them.

This is the xml for the check/uncheck all checkboxes and lines up fine.

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/light_blue"
        android:orientation="horizontal">

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <CheckBox
                android:id="@+id/checkBox1"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:width="60dp"
                android:background="@color/light_blue"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:text="Ck all"
                android:textSize="15dp"
                android:textStyle="bold" />
            <CheckBox
                android:id="@+id/checkBoxI"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@color/light_blue"
                android:focusable="false"
                android:focusableInTouchMode="false" />

            <CheckBox
                android:id="@+id/checkBoxII"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@color/light_blue"
                android:focusable="false"
                android:focusableInTouchMode="false" />

etc.

This is for column headings and does not line up.

   <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/light_blue"
        android:orientation="horizontal">

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:width="60dp"
                android:gravity="center"
                android:background="@color/light_blue"/>
            <TextView
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@color/light_blue"
                android:gravity="center"
                android:text="I"/>
            <TextView
                android:layout_height="match_parent"
                android:gravity="center"
                android:layout_weight="1"
                android:background="@color/light_blue"
                android:text="I"/>

etc

This is another attempt that also does not line up.

   <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/light_blue"
        android:orientation="horizontal">

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_height="match_parent"
                android:width="60dp"
                android:layout_weight="1"
                android:text=""
                android:gravity="center"
                android:background="@color/light_blue"
                android:focusable="false"
                android:focusableInTouchMode="false"/>
            <TextView
                android:id="@+id/keycode"
                android:layout_height="match_parent"
                android:gravity="center"
                android:layout_weight="1"
                android:background="@color/light_blue"
                android:text="I"
                android:textStyle="bold" />

            <TextView
                android:layout_height="match_parent"
                android:gravity="center"
                android:layout_weight="1"
                android:background="@color/light_blue"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:text="II"
                android:textStyle="bold" />

etc.

I've tried many different combinations of text alignment, and even tried to force the column widths which of course wouldn't work across devices. I've spent all day on this and still have no clue. Any help appreciated.




Aucun commentaire:

Enregistrer un commentaire