relativeLayout 按钮上方居中的两个 TextView
因此,在我的布局中,我在同一行上有两个按钮,一个左对齐,一个右对齐。我还在按钮上方设置了 TextView 作为标签,但它们也分别左对齐和右对齐。我希望它们位于按钮上方的中心并彼此在同一行,但如果不明确设置坐标,我无法弄清楚如何做到这一点,这会在某些手机上中断。我尝试设置各种权重和布局选项,但它只是无法按我想要的方式工作。有没有办法在相对布局中做到这一点?或者也许这是不可能的。
提前致谢。
So in my layout, I've got two buttons on the same line, one left aligned and one right aligned. I also have TextViews above the buttons to serve as labels, but they too are aligned left and right respectively. I'd like them to instead be centered above the buttons and on the same line as one another, but I can't figure out how to do this without explicitly setting coordinates, which will then break on some phones. I tried setting various weights and layout options, but it just doesn't work how I'd like. Is there a way to do this in a RelativeLayout? Or maybe it's just not possible.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚尝试了两个级别的relativelayers,这是输出:

和代码:
I've just tried with two levels of RelativeLayers, and here is the output:

and the code:
创建一个包含 2 列和 2 行的表格布局。
使第一个和最后一个列可收缩,中间列可拉伸。
将标签放在 1 和 2 处,将按钮放在 3 和 4 处。
然后将所有列内容居中。
Create a tablelayout with 2 columns and 2 rows.
Make first and last columnn shrinkable, and middle column stretchable.
Put your labels at 1 and 2, and buttons at 3 and 4.
Then center all column content.