Android 布局操作栏按钮
抱歉这个有点无聊的问题,但我试图在“操作栏”上布局按钮,但使用“layout_alignRight”等遇到了麻烦。我想要实现的目标如下:
|[button1] _ _ _ 空白 _ _ _ [button2] [button3] [button4]|
我有一个relativelayout包含四个按钮应该放置的位置,并且我尝试了以下代码但无济于事:
<RelativeLayout android:id="@+id/actionBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#666666" >
<Button android:id="@+id/button1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignLeft="@id/actionBar"
android:background="@drawable/buttonImg" />
<Button android:id="@+id/button4"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignRight="@id/actionBar"
android:background="@drawable/buttonImg" />
<Button android:id="@+id/button3"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toLeftOf="@id/button2"
android:background="@drawable/buttonImg" />
<Button android:id="@+id/button2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toLeftOf="@id/button3"
android:background="@drawable/buttonImg" />
</RelativeLayout>
按钮似乎总是被拉伸得很远,或者全部都堆积在彼此之上。有谁知道如何实现我正在寻找的间距?
谢谢!!!
Sorry for the somewhat boring question, but I am trying to lay out buttons on an "action bar" and am running into trouble using "layout_alignRight" and the like. What I want to achieve is the following:
|[button1] _ _ _ empty space _ _ _ [button2] [button3] [button4]|
I have a RelativeLayout enclosing where the four buttons should sit, and I've tried the following code to no avail:
<RelativeLayout android:id="@+id/actionBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#666666" >
<Button android:id="@+id/button1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignLeft="@id/actionBar"
android:background="@drawable/buttonImg" />
<Button android:id="@+id/button4"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignRight="@id/actionBar"
android:background="@drawable/buttonImg" />
<Button android:id="@+id/button3"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toLeftOf="@id/button2"
android:background="@drawable/buttonImg" />
<Button android:id="@+id/button2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toLeftOf="@id/button3"
android:background="@drawable/buttonImg" />
</RelativeLayout>
The buttons always seem to get stretched way out, or to all get piled up on top of each other. Does anyone know how to achieve the spacing I'm looking for?
Thanks!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅使用相对布局时,您必须锚定最左侧的按钮,然后是最右侧的按钮,然后添加与最右侧按钮左侧对齐的其他两个按钮:
With using only relative layout, you have to anchor the left most button, then the rightmost button, and then add the two other buttons aligning left of the rightmost button: