[英]Recyclerview with match_parent for width and height returns fixed size error
[英]How to change the Button size in a GridLayout to “match_parent”?
我目前有这个:
我正在尝试得到这个:
我已经尝试了一个多小时,但似乎无法正常工作。 请在下面查看我的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>
我该如何更改他占据整个位置的最后一个Button,例如“ match_parent”? 谢谢
请尝试使用
android:layout_width="match_parent"
而不是android:layout_width="100dp"
将android:layout_columnSpan="2"
添加到android:id="@+id/button5"
。 这将使按钮跨越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.