【发布时间】:2019-03-03 21:36:53
【问题描述】:
我有一个垂直线性布局,它包裹了另一个垂直线性布局。
如何使内部线性布局垂直居中?
据我所知,垂直线性布局会强制其子级从左上角开始定位。
<LL vertical> //outer
<LL vertical> //inner - is used to group
<textView> //just a view to be vertically centered
</textView>
<LL vertical>
<anotherView/>
</LL vertical>
当我删除外部线性布局时,我看到内部布局垂直居中于其父级。
如何实现相同的垂直居中?分组需要外部线性布局。
我可以用水平LL包裹垂直LL,然后它的儿子的vertical_center将生效。但这不是浪费吗?
【问题讨论】:
-
必须是线性布局吗?您可以只使用相对布局并赋予属性 android:centerVeritical="true"
-
或者使用约束布局
标签: android android-layout android-linearlayout center