Android: how to center view within column of TableLayout?

六月ゝ 毕业季﹏ 提交于 2019-12-01 02:45:59

On the CheckBox, instead of setting android:gravity="center_horizontal", you want to set android:layout_gravity="center_horizontal"

android:gravity controls how the view lays out its contents inside its own container, and since you have the width set to "wrap_content", there is no void space for the CheckBox to center itself inside of.

android:layout_weight tells the parent view (in this case the TableRow) how to position the child, so it will center the CheckBox inside the table cell.

use

android:layout_gravity="center"

it will centralize checkbox whether it's width is hardcoded or "wrap_content"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!