My problem is that the button size change when I type more text in the Button:
My GridLayout:
The problem arises when I type more text in the Button:
My 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:layout_height="match_parent">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="Buttonnnnnnnnnnn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:id="@+id/button1" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:id="@+id/button2" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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="wrap_content"
android:layout_height="wrap_content"
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="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:id="@+id/button5"
android:layout_row="2"
android:layout_column="0" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:id="@+id/button6"
android:layout_row="2"
android:layout_column="1" />
</GridLayout>
</LinearLayout>
Changing
android:layout_width="wrap_content"
android:layout_height="wrap_content"
to
android:layout_width="match_parent"
android:layout_height="match_parent"
does not work
I don't want that the Button size changed. How can I do that?
Keep the layout:height
and layout:width
constant as some 'xdp'. Because, if you make it wrap content , it will automatically adjust according to the text size to wrap the whole text inside it.
您正在使用GridLayout通过权重来管理宽度和高度,因此可以在Button大小上设置0dp
。
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.