Hello,
Welcome to our Microsoft Q&A platform!
Are there any good tutorials or examples of how to use GridLayout when sizes need to be dynamic?
For this function, try the two solution below:
1.Try to set android:layout_columnWeight
for each cell and set android:layout_width
to wrap_content. The width of the editText will be changed when inputting words to it continously.
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="1"
android:columnCount="2">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="0"
android:layout_columnWeight="1"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="1"
android:gravity="center_horizontal"
android:layout_columnWeight="1"/>
</GridLayout>
2.Or using a LinearLayout to wrap the views of the row cells, the views's width will work like the Auto style
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="1"
android:columnCount="2">
<LinearLayout
android:layout_columnSpan="2"
android:layout_row="0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:text="button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:hint="edit test"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</GridLayout>
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
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.