gpt4 book ai didi

Android 布局操作栏按钮

转载 作者:行者123 更新时间:2023-11-29 02:10:36 25 4
gpt4 key购买 nike

很抱歉这个有点无聊的问题,但我正在尝试在“操作栏”上布置按钮,但在使用“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>

按钮似乎总是被拉长,或者全部堆叠在一起。有谁知道如何实现我正在寻找的间距?

谢谢!!!

最佳答案

如果只使用相对布局,你必须锚定最左边的按钮,然后是最右边的按钮,然后添加另外两个按钮与最右边的按钮左对齐:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button android:id="@+id/b1" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Button1"></Button>
<Button android:id="@+id/b4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Button4"></Button>
<Button android:id="@+id/b3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/b4"
android:text="Button3"></Button>
<Button android:id="@+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/b3"
android:text="Button2"></Button>
</RelativeLayout>

关于Android 布局操作栏按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7670010/

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