My buttons are being overflow inside the gridlayout because their length are being long from the start unnecessarily. I just want to set them wrap_content
to all of them. I was doing this tutorial. Here's my code.
<GridLayout
android:id="@+id/characterLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/keyOptionLayout"
android:layout_below="@id/tvLotteryNumber"
android:background="#33000000"
android:columnCount="5"
android:orientation="horizontal">
<Button
android:layout_row="0"
android:text="a" />
<Button
android:layout_row="0"
android:text="b" />
<Button
android:layout_row="0"
android:text="c" />
<Button
android:layout_row="0"
android:text="d" />
<Button
android:layout_row="0"
android:text="e" />
</GridLayout>
Removing android_layout_row="0"
lines doesn't change anything. Here's how they displayed.
You can add
android:layout_width="0dp"
android:layout_height="0dp'
to your buttons and add
grid:layout_columnWeight="1"
grid:layout_rowWeight="1"
to your buttons. Don't forget to add xmlns:android="http://schemas.android.com/apk/res/android"
namepsace to your GridLayout
Using android.support.v7.widget.GridLayout
solved the issue.
compile 'com.android.support:gridlayout-v7:25.3.1'
Result:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.