我在 LinearLayout 中有一些垂直方向的元素
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical" >
<TextView
... />
<Button
... />
</LinearLayout>
这些元素不会占据应用程序的整个垂直空间,我希望它们垂直居中。我该怎么做?
最佳答案
Layout_gravity="center_vertical"不适用于垂直的 LinearLayout。
我想说你可以在 LinearLayout 上设置 android:layout_height="match_parent"
和 android:gravity="center_vertical"
。
关于android - 如何在 xml 中将整个 LinearLayout 居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14009554/