Hello,
Welcome to our Microsoft Q&A platform!
no problem using layout_columnWeight="1" and layout_width="0" in the buttons. ... if I use a value of wrap_content it displays nothing.
When setting layout_width
to wrap_content
, the gridLayout will caculate the width of the content. Because the layout_width
of the two buttons' was set to 0, the width of the gridLayout will also be 0.
To fix this, please change the layout_width
of the two buttons to wrap_content
. This will also work when setting gridLayout's widht to match_parent
.
<GridLayout
android:padding="2dp"
android:rowCount="1"
android:background="#0f0"
android:columnCount="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:text="Button1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_row="0"
android:layout_columnWeight="1"
android:layout_column="0"/>
<Button
android:text="Button2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_row="0"
android:layout_columnWeight="1"
android:layout_column="1"/>
</GridLayout>
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.