android的Gridlayout问题

imsorrybut 2015-05-19 09:36:48
android新手来的,我想让GridLayout第一行的四个按钮填充第一行,为何最后总是留有空隙呢?
代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="100px"
android:orientation="vertical" >

<GridLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnCount="4"
android:orientation="horizontal"
android:rowCount="1" >

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/backgroundphoto"
android:drawableTop="@drawable/call"
android:text="@string/phone" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/backgroundphoto"
android:drawableTop="@drawable/star"
android:text="@string/collect" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/backgroundphoto"
android:drawableTop="@drawable/single"
android:text="@string/communicater" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/backgroundphoto"
android:drawableTop="@drawable/doubles"
android:text="@string/doubles" />
</GridLayout>
</LinearLayout>

</LinearLayout>

...全文
295 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
come_on_Angelababy 2015-05-28
  • 打赏
  • 举报
回复
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="100px" android:orientation="horizontal" > <Button android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/backgroundphoto" android:drawableTop="@drawable/call" android:text="@string/phone" /> <Button android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/backgroundphoto" android:drawableTop="@drawable/star" android:text="@string/collect" /> <Button android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/backgroundphoto" android:drawableTop="@drawable/single" android:text="@string/communicater" /> <Button android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/backgroundphoto" android:drawableTop="@drawable/doubles" android:text="@string/doubles" /> </LinearLayout> </LinearLayout>
SQTTTTTTT 2015-05-22
  • 打赏
  • 举报
回复
在布局文件中,每个按钮加一句 android:layout_weight="1"
come_on_Angelababy 2015-05-21
  • 打赏
  • 举报
回复
每个button价格weight=“1”就ok了
imsorrybut 2015-05-19
  • 打赏
  • 举报
回复
引用 10 楼 hjq2013 的回复:
[quote=引用 9 楼 imsorrybut 的回复:] [quote=引用 8 楼 hjq2013 的回复:] [quote=引用 7 楼 imsorrybut 的回复:] [quote=引用 6 楼 hjq2013 的回复:] 什么错???
改成LinearLayout的话又变成之前那样了[/quote]原来什么样?[/quote][/quote] <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="100px" android:orientation="horizontal" android:gravity="center" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/backgroundphoto" android:drawableTop="@drawable/call" android:text="@string/phone" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/backgroundphoto" android:drawableTop="@drawable/star" android:text="@string/collect" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/backgroundphoto" android:drawableTop="@drawable/single" android:text="@string/communicater" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/backgroundphoto" android:drawableTop="@drawable/doubles" android:text="@string/doubles" /> </LinearLayout> </LinearLayout> [/quote] 还是没有把第一行填充啊
引用 10 楼 hjq2013 的回复:
[quote=引用 9 楼 imsorrybut 的回复:] [quote=引用 8 楼 hjq2013 的回复:] [quote=引用 7 楼 imsorrybut 的回复:] [quote=引用 6 楼 hjq2013 的回复:] 什么错???
改成LinearLayout的话又变成之前那样了[/quote]原来什么样?[/quote][/quote] <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="100px" android:orientation="horizontal" android:gravity="center" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/backgroundphoto" android:drawableTop="@drawable/call" android:text="@string/phone" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/backgroundphoto" android:drawableTop="@drawable/star" android:text="@string/collect" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/backgroundphoto" android:drawableTop="@drawable/single" android:text="@string/communicater" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/backgroundphoto" android:drawableTop="@drawable/doubles" android:text="@string/doubles" /> </LinearLayout> </LinearLayout> [/quote] 还是没有把第一行完全填充啊
Hare_ 2015-05-19
  • 打赏
  • 举报
回复
引用 9 楼 imsorrybut 的回复:
[quote=引用 8 楼 hjq2013 的回复:] [quote=引用 7 楼 imsorrybut 的回复:] [quote=引用 6 楼 hjq2013 的回复:] 什么错???
改成LinearLayout的话又变成之前那样了[/quote]原来什么样?[/quote][/quote] <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="100px" android:orientation="horizontal" android:gravity="center" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/backgroundphoto" android:drawableTop="@drawable/call" android:text="@string/phone" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/backgroundphoto" android:drawableTop="@drawable/star" android:text="@string/collect" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/backgroundphoto" android:drawableTop="@drawable/single" android:text="@string/communicater" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/backgroundphoto" android:drawableTop="@drawable/doubles" android:text="@string/doubles" /> </LinearLayout> </LinearLayout>
imsorrybut 2015-05-19
  • 打赏
  • 举报
回复
引用 8 楼 hjq2013 的回复:
[quote=引用 7 楼 imsorrybut 的回复:]
[quote=引用 6 楼 hjq2013 的回复:]
什么错???

改成LinearLayout的话又变成之前那样了[/quote]原来什么样?[/quote]
Hare_ 2015-05-19
  • 打赏
  • 举报
回复
引用 7 楼 imsorrybut 的回复:
[quote=引用 6 楼 hjq2013 的回复:] 什么错???
改成LinearLayout的话又变成之前那样了[/quote]原来什么样?
imsorrybut 2015-05-19
  • 打赏
  • 举报
回复
引用 6 楼 hjq2013 的回复:
什么错???
改成LinearLayout的话又变成之前那样了
Hare_ 2015-05-19
  • 打赏
  • 举报
回复
什么错???
imsorrybut 2015-05-19
  • 打赏
  • 举报
回复
引用 4 楼 hjq2013 的回复:
[quote=引用 3 楼 imsorrybut 的回复:] [quote=引用 1 楼 hjq2013 的回复:] 图片宽度的问题把,设置button的layout_gravity="fill"试试
按钮大小不一样了[/quote]把4个按钮外面的gridlayout去掉呢,用水平的linearlayout呢[/quote] 有报错了
Hare_ 2015-05-19
  • 打赏
  • 举报
回复
引用 3 楼 imsorrybut 的回复:
[quote=引用 1 楼 hjq2013 的回复:] 图片宽度的问题把,设置button的layout_gravity="fill"试试
按钮大小不一样了[/quote]把4个按钮外面的gridlayout去掉呢,用水平的linearlayout呢
imsorrybut 2015-05-19
  • 打赏
  • 举报
回复
引用 1 楼 hjq2013 的回复:
图片宽度的问题把,设置button的layout_gravity="fill"试试

按钮大小不一样了
imsorrybut 2015-05-19
  • 打赏
  • 举报
回复
可以,可是4个按钮大小不一样啊
Hare_ 2015-05-19
  • 打赏
  • 举报
回复
图片宽度的问题把,设置button的layout_gravity="fill"试试

80,351

社区成员

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

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