问个关于linerlayout_weight属性与button背景的问题!

athenalux 2012-06-13 05:03:58
我想实现一个水平的linerlayout,基中放4个button,并且使这4个button点的比例分别为:20%,20%,20%,40%。 按说设定layout_weight属性就可以了,但出来的效果总是不对,请高手看看怎么回事?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1"
/>
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1"
/>
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1"
/>
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="2"
/>
</LinearLayout>
</LinearLayout>

怎么会这样,求解决!!


另外,再问下button控件设定background属性后,为什么text设定的属性不显示了?有什么办法能让它正常显示text属性么?
...全文
156 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
athenalux 2012-06-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
宽度的参数写错了

里面的每一个Button的宽度,不应该是match_parent

另外,你说的Button设定背景属性后怎么什么不显示了,,,,我没有理解,,,,,
[/Quote]
就是比如说这样:
android:background="@drawable\bg1"
android:text="button1"
这样以后,按钮只显示背景图片,而文字button1就没有了。
横龙村夫 2012-06-13
  • 打赏
  • 举报
回复
把每一个Button 的宽度设成0
世界你好 2012-06-13
  • 打赏
  • 举报
回复
宽度的参数写错了

里面的每一个Button的宽度,不应该是match_parent

另外,你说的Button设定背景属性后怎么什么不显示了,,,,我没有理解,,,,,
JewLeo 2012-06-13
  • 打赏
  • 举报
回复
同意
[Quote=引用 6 楼 的回复:]
每个button 的layout_width 都因该是fill_parent
[/Quote]
xl13071231235 2012-06-13
  • 打赏
  • 举报
回复
每个button 的layout_width 都因该是fill_parent
clusterer 2012-06-13
  • 打赏
  • 举报
回复
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button"/>
<Button
android:id="@+id/button2"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button"/>
<Button
android:id="@+id/button3"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button"
android:background="@android:color/white"/>
<Button
android:id="@+id/button4"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Button"/>
</LinearLayout>
</LinearLayout>


这样就可以了。。。
至于你说的button控件设定background属性后,为什么text设定的属性不显示了?
它的text还是显示的呀,估计是你设置的背景颜色的问题。。。改下字体颜色试试。。。
糊涂人 2012-06-13
  • 打赏
  • 举报
回复
laytou_wieght的值越大,所占的宽度是越小的,不过好像也不完全是成反比,试过weight的值分别为4、4、4、3,比较接进楼主想要的效果

80,493

社区成员

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

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