如何让一个线性布局中的三个按钮均匀的排列?

ynduanlian 2012-10-15 04:37:57
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="简单"
android:layout_margin="10px" />

<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="中等"
android:layout_margin="10px" />

<Button
android:id="@+id/button3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="较难"
android:layout_margin="10px" />

</LinearLayout>

试了半天,不知道要怎么设置属性才能让三个按钮在一条线上均匀的分布?
...全文
3461 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
李狗蛋52635 2012-10-15
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

均匀的居中怎么办呢,现在都是从左边排起?
我想在宽的空间上,每个按钮都在33%的空间中居中?
[/Quote]

1.可以每个button外面套一个LinearLayout之类的容器,容器均匀分页,button在容器里居中;
2.3个button均匀分布,然后为每个button设置layout_marginLeft和layout_marginRight为一样的值就好了。
李狗蛋52635 2012-10-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

1. LinearLayout要有orientation属性;
2. 3个Button的android:layout_width="fill_parent",这是要闹哪样?
3. 均匀是吧,layout_width=0dp并且layout_weight都设为一样的值就好了。
[/Quote]

记说了,3是以水平分布为例-v-
ynduanlian 2012-10-15
  • 打赏
  • 举报
回复
均匀的居中怎么办呢,现在都是从左边排起?
我想在宽的空间上,每个按钮都在33%的空间中居中?
a1150247879 2012-10-15
  • 打赏
  • 举报
回复
三个都加上android:layout_weight=1并且把android:layout_width="wrap_content"
李狗蛋52635 2012-10-15
  • 打赏
  • 举报
回复
1. LinearLayout要有orientation属性;
2. 3个Button的android:layout_width="fill_parent",这是要闹哪样?
3. 均匀是吧,layout_width=0dp并且layout_weight都设为一样的值就好了。

80,361

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧