[英]How to change the Button size in a GridLayout to “match_parent”?
I currently have this: 我目前有这个:
And I'm trying to get this: 我正在尝试得到这个:
I have tried for over an hour now, but cannot seem to get it working. 我已经尝试了一个多小时,但似乎无法正常工作。 Please take a look at my XML below.
请在下面查看我的XML。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:background="@drawable/png1"
android:layout_height="match_parent">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="Button"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:id="@+id/button1" />
<Button
android:text="Button"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:id="@+id/button2" />
<Button
android:text="Button"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:id="@+id/button3"
android:layout_row="1"
android:layout_column="1" />
<Button
android:text="Button"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:id="@+id/button4"
android:layout_row="1"
android:layout_column="0" />
<Button
android:text="Button"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:id="@+id/button5"
android:layout_row="2"
android:layout_column="0" />
</GridLayout>
</LinearLayout>
How can i change the last Button that he takes the whole place, like "match_parent"? 我该如何更改他占据整个位置的最后一个Button,例如“ match_parent”? Thanks
谢谢
please try to use this 请尝试使用
android:layout_width="match_parent"
instead of android:layout_width="100dp"
而不是
android:layout_width="100dp"
Add android:layout_columnSpan="2"
to android:id="@+id/button5"
. 将
android:layout_columnSpan="2"
添加到android:id="@+id/button5"
。 This will make the button span 2 columns. 这将使按钮跨越2列。
<Button
android:text="Button"
android:layout_columnSpan="2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:id="@+id/button5"
android:layout_row="2"
android:layout_column="0" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.