Android 在TableRow列中使用布局权重的中心视图(复选框)
我有一个我正在膨胀的布局,以便动态地添加到。我使用布局权重将列拉伸到所需的宽度 表格放在一个表格中,这样我可以在生成的行之间滚动。我还有一个放在顶部的表格标题。我这样做是因为我不想滚动标题。这也是为什么我不使用布局跨度而不是布局权重 问题是TableRow中的一个视图是a,我希望它居中,但由于layout_width属性为“0”,我无法使用layout_gravity=“center”将其居中 以下是xml文件:Android 在TableRow列中使用布局权重的中心视图(复选框),android,android-layout,Android,Android Layout,我有一个我正在膨胀的布局,以便动态地添加到。我使用布局权重将列拉伸到所需的宽度 表格放在一个表格中,这样我可以在生成的行之间滚动。我还有一个放在顶部的表格标题。我这样做是因为我不想滚动标题。这也是为什么我不使用布局跨度而不是布局权重 问题是TableRow中的一个视图是a,我希望它居中,但由于layout_width属性为“0”,我无法使用layout_gravity=“center”将其居中 以下是xml文件: <?xml version="1.0" encoding
<?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>
这就是它的样子:
这就是我希望它看起来的样子:
*颜色仅用于代表性目的。它们可以被忽略
如果有人能帮忙,我将非常感激。谢谢试试这个:
<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>
谢谢。你让我走上了正确的道路。我最终使用了布局为_width=“0dp”的RelativeLayout,因为必须使用基于0的宽度,而且RelativeLayout比LinearLayout更轻。它似乎对性能没有明显的影响。再次感谢这似乎可行,但为什么将复选框封装在另一个布局中是唯一可行的解决方案?看起来更像是一种黑客行为,而不是一种正确的方式。