相对布局的问题
我在使用RelativeLayout 时遇到一些问题。
我想要 4 个大小相等的水平空间。当您将它们包含在 LinearLayout 中时,这很简单。您只需将它们的layout_width设置为“fill_parent”并将其layout_weight设置为“1”。但是,我怎样才能在RelativeLayout中实现这一点呢?我不知道 4 个空间中每个空间的宽度尺寸,因为 Android 手机的尺寸可能不同,我希望它是动态的。
有想法吗?
如果有替代解决方案,这就是我想要做的:这是我绘制的快速模型。我有一个工具栏,当用户第一次访问屏幕时,我希望一些图像位于屏幕顶部。这些图像中的每一个都包含一个箭头,以及一些与该箭头想要指向的内容相关联的文本。因此,您可以看到我需要如何相对于 4 个空间之一放置图像,并且图像本身可以扩展空间的宽度。 http://i42.tinypic.com/2yxi683.jpg
更新:我找到了解决方案,虽然我想找到一个更好的。我以编程方式获取了 4 个视图,确定了显示器的宽度,将该数字除以 4,并将每个视图的宽度设置为该值。
I'm having some trouble using RelativeLayout.
I want 4 equally sized spaces oriented horizontally. This is simple enough when you contain them inside a LinearLayout. You just set their layout_width to "fill_parent" and their layout_weight to "1". However, how can I accomplish this inside a RelativeLayout? I don't know the width dimension of each of the 4 spaces as Android phones can be of differing sizes and I want this to be dynamic.
Ideas?
In case there's an alternate solution, here is what I'm trying to do: Here's a quick mockup I drew. I have a toolbar and the first time the user visits the screen I'd like some images to lay over the top of the screen. Each of these images contains an arrow with some text associated with whatever the arrow is intended to point to. So you can see how I need to place the image relative to one of the 4 spaces and the images themselves can extend the width of the space. http://i42.tinypic.com/2yxi683.jpg
Update: I've found a solution, though I would like to find a better one. I've grabbed the 4 Views programmatically, determined the display's width, divided that number by 4, and set the width of each View to that value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能想发布您真正想要的布局的模型,以防万一您可以使用另一种方法,有人可以想出,但如果您真的不能使用嵌套的 LinearLayout 方法,您可能会拥有创建自定义布局。
You might want to post a mockup of what you really want for the layout in case there's another approach you can use that someone can come up with, but if you really can't use the nested LinearLayout approach, you're probably going to have to create a custom layout.
创建一个LinearLayout并将4个视图放置在LinearLayout中。然后只需将LinearLayout 添加到RelativeLayout 中即可。这是最简单的方法。
Create a LinearLayout and place the 4 view in the LinearLayout. Then just add the LinearLayout to the RelativeLayout. That is the easiest way.