У меня есть макет, который я надуваю, чтобы динамически добавлять TableRows в TableLayout .Я использую layout_weight, чтобы растянуть столбцы до желаемой ширины.
Таблица помещена в ScrollView , чтобы я мог прокручивать сгенерированные строки.У меня также есть заголовок таблицы, который я помещаю в LinearLayout сверху.Я сделал это, потому что я не хочу прокручивать заголовок.Вот почему я не использую layout_span вместо layout_weight.
Проблема в том, что одним из представлений в TableRow является CheckBox , и я хочу, чтобы он был центрирован, но поскольку layout_widthатрибут '0'. Я не могу использовать layout_gravity = "center" для его центрирования.
Вот XML-файл:
<?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>
Вот как это выглядит: ![CheckBox not centered](https://i.stack.imgur.com/6ElEM.png)
Вот как я хочу, чтобы это выглядело: ![enter image description here](https://i.stack.imgur.com/Z0WDL.png)
* Цвета приведены только для ознакомительных целей.Их можно игнорировать.
Я был бы очень признателен, если бы кто-то мог помочь.Спасибо