Adding Spinner to GridLayout seems to break the layout. I prepared a minimal working example to illustrate the problem:
I need a grid with labels on the left and controls on the right. The controls on the right should occupy the remaining space. Here is a simple example:

Replacing one of the I / O controls causes the right column to go beyond the borders of the screen, resulting in an ugly layout.

Why is this happening, and how can I avoid it?
Here is the code for the first example:
<?xml version="1.0" encoding="utf-8"?> <GridLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:columnCount="2" > <TextView android:layout_gravity="left" android:text="TextView" /> <EditText android:layout_gravity="fill_horizontal" android:hint="EditText" /> <TextView android:layout_gravity="left" android:text="TextView" /> <EditText android:layout_gravity="fill_horizontal" android:hint="EditText" /> </GridLayout>
And here is the code for the second image. The only difference is that the first EditText was replaced by Spinner:
<?xml version="1.0" encoding="utf-8"?> <GridLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:columnCount="2" > <TextView android:layout_gravity="left" android:text="TextView" /> <Spinner android:id="@+id/spinner1" android:layout_gravity="fill_horizontal" /> <TextView android:layout_gravity="left" android:text="TextView" /> <EditText android:layout_gravity="fill_horizontal" android:hint="EditText" /> </GridLayout>
android layout android-gridlayout
Heinzi
source share