我希望按钮保持其原始大小(包装内容),但它们要在该逻辑单元格位置对齐。这有可能吗?我是说,我想要的是,
|[Lisa]_______|[Simpson]____|不,
|[___Lisa____]|[__Simpson__]|或,
|[Lisa]|[Simpson]___________|以下代码不起作用。
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Lisa"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Simpson"/>
</TableRow>发布于 2018-02-07 18:52:05
默认情况下,TableLayout将其项目居中。您可以使用的是LinearLayout,如下所示:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Lisa"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Simpson"/>
</LinearLayout>这会均匀地划分两个按钮的间距,但不会使每个按钮居中。这是它看起来的样子。

https://stackoverflow.com/questions/48658693
复制相似问题