如何让几个图片Button在一行中显示,并且间距均匀 如题所问需要在一行中排列4个图片按钮,如何让其自动排列达到间距均匀的效果?用什么layout容器方便?button需要做什么设置 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 LinearLayout,每个buttonandroid:layout_width="0px"android:layout_weight="1" 一般用LinearLayout如果想要button均匀排列,一般要用到就是设置它的宽度和权值!button里面一般设置:android:layout_widthandroid:layout_weight=“相同的值” 使用LinearLayout <LinearLayout android:id="@+id/widget0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:text="delete" android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20px" android:layout_marginRight="20px"> </Button></LinearLayout>每个button这样设置, 就ok了 我觉得 TableLayout方式布局比较好点<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:shrinkColumns="0,1,2"><!-- have an eye on ! --> <TableRow><!-- row1 --> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" Button1" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" Button2" android:layout_column="1" /> 再填2个 用GridView, 网格视图组件, 每一个单元格可以代表一个View对象, 这里可以是Button, 在代码中动态生成所需按钮即可 既然还没结贴,那就说下我的方法吧使用LinearLayout,每个Button的 layout_weight设为1src设为Button的图片背景background设为#00000000这样各个Button等间距,图片还不会背拉伸 方法挺多的,只是使用的一些区别而已,LinaerLayout、TableLayout、RelativeLayout等,都可以实现该效果看楼主擅长用哪种了 android 在activity中绑定一个服务失败 新手求一个简单问题 无法监听到onTouch事件的问题 android开发MP3播放器遇到的一个棘手问题 哪位有图片浏览器源码吗 eclipse android 问题 webview + scrollView进去黑屏,求高手解决 android 移植问题,大家讨论下! Android手机屏幕变成LED显示屏 代码怎么写 布局问题 推送技术在android如何实现 关于webview的缓存问题
android:layout_weight="1"
如果想要button均匀排列,一般要用到就是设置它的宽度和权值!
button里面一般设置:
android:layout_width
android:layout_weight=“相同的值”
android:id="@+id/widget0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"> <Button android:text="delete"
android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20px"
android:layout_marginRight="20px">
</Button></LinearLayout>每个button这样设置, 就ok了
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:shrinkColumns="0,1,2"><!-- have an eye on ! -->
<TableRow><!-- row1 -->
<Button android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Button1"
/>
<Button android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Button2"
android:layout_column="1"
/>
再填2个
使用LinearLayout,每个Button的 layout_weight设为1
src设为Button的图片背景
background设为#00000000
这样各个Button等间距,图片还不会背拉伸
LinaerLayout、TableLayout、RelativeLayout等,都可以实现该效果
看楼主擅长用哪种了