I have a layout which I am inflating in order to dynamically add TableRows into a TableLayout. I use layout_weight to stretch the columns to the desired width.
The table is put inside a ScrollView so I can scroll between the generated rows. I also have a table header that I put in a LinearLayout on top. I did this because I don't want to scroll the header. That is also why I don't use layout_span instead of layout_weight.
The problem is that one of the Views in the TableRow is a CheckBox and I want it centered, but since the layout_width attribute is '0' I can not use layout_gravity="center" to center it.
Here is the xml file:
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/order_form_line_TableRow"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/order_table_row_product_description_TextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.22"
android:maxLines="2"
android:textSize="18sp" />
<CheckBox
android:id="@+id/order_table_row_present_CheckBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.08" />
<EditText
android:id="@+id/order_table_row_facings_EditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.10"
android:inputType="number" />
<EditText
android:id="@+id/order_table_row_free_cu_given_EditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.10"
android:inputType="number" />
<EditText
android:id="@+id/order_table_row_order_quantity_EditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.10"
android:inputType="number" />
<EditText
android:id="@+id/order_table_row_free_order_EditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.10"
android:inputType="number" />
<Spinner
android:id="@+id/order_table_row_wholesaler_Spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.15" />
<EditText
android:id="@+id/order_table_row_delivery_date_EditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.15"
android:ellipsize="end"
android:inputType="date"
android:singleLine="true" />
</TableRow>
This is how it looks:
This is how I want it to look:
*The colors are for representational purpose only. They can be ignored.
I would very much appreciate it if someone could help. Thank you
try this :
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:gravity="center"
android:layout_weight="0.08"
android:layout_height="fill_parent" >
<CheckBox
android:id="@+id/order_table_row_present_CheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With