gpt4 book ai didi

android - 线性布局 : How to position elements

转载 作者:行者123 更新时间:2023-11-30 04:20:05 24 4
gpt4 key购买 nike

我知道当我想要彼此相对的东西时我可以使用相对布局。但是如果我使用线性布局来简单定位元素,那么我应该能够做到这一点吧?我的问题是,如果我在线性布局(表格及其标题)中有 textview 和 tablelayout,我怎样才能使标题水平居中并且表格垂直居中(假设它占用屏幕的整个宽度)

<LinearLayout 
android:layout_width = "fill_parent" android:layout_height = "fill_parent"
android:orientation= "veritical" >
<TextView
android:layout_width = "wrap_content" android:layout_height = "wrap_content"
android:layout_gravity = "center_horizontal" />

<tablelayout
android:layout_width = "fill_parent" android:layout_height = "wrap_content"
android:layout_gravity = "center_vertical" />
</LinearLayout>

但上面的方法不起作用(在 table 上没有居中的 veritcall)我希望它像

***************TEXT VIEW**************
*
*
*
TABLE
*
*
*

你有什么建议???

最佳答案

您需要将您的 TextView layout_height 设置为“fill_parent”,并且您的 layout_gravity 将起作用。目前, TextView 仅与内容一样宽。与表格相同,layout_height 需要为 fill_parent。

不过,我总是建议尽可能使用相对布局。

关于android - 线性布局 : How to position elements,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9402489/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com