Spinner floats down with horizontal alignment

If I add a counter in a horizontal LinearLayout or in a row in a table, for example, as follows:

<LinearLayout android:id="@+id/linearLayout3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" > </EditText> <Spinner android:id="@+id/spinner1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" /> </LinearLayout> 

Twist swims. It pops up on Android 2.2, Android 2.3 and Android 3.2, but it works well in Android 4.0, they fixed it. But is there a way to align it with other views like EditText on Android 2.3.

By float down, I mean:

 *********************** * if EditText is here * ************************ *********************** * Spinner will be here * ************************ 
+7
source share
7 answers

Old post, but it can help:

the baselineAligned value is not necessary for true, since it is the default value (explained here: http://developer.android.com/reference/android/widget/LinearLayout.html#attr_android:baselinealigned )

I fixed it with hardcoding height for both textview and spinner, and set baselineAligned to FALSE.

+3
source

Spinner is smaller than EditText, so the way to align it is to add android: layout_height = "match_parent" to Spinner and save LinearLayout and EditText using wrap_content.

+3
source

I ran into the same problem before, and I understood the answer after trying and modifying my xml, here is my xml code:

 <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/linearlayout1" android:orientation="horizontal" android:gravity="bottom"> <android.support.design.widget.TextInputLayout android:id="@+id/text_input_layout" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="50"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/editText" android:textSize="20dp" android:hint="Duration" android:layout_gravity="left" android:gravity="center" /> </android.support.design.widget.TextInputLayout> <Spinner android:id="@+id/spinner" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_weight="50" /> 

Just set the gravity your LinearLayout to bottom and solve your problem.

+2
source

You should add the following to your editText:

 android:layout_gravity="center_vertical" 
+1
source

In linearlayout mode, the orientation is horizontal. Significant elements are placed side by side. However, your EditText and Spinner have android: layout_width = "fill_parent". So you want to place your EditText and Spinner side by side, but you also want them to populate_parent ...

What would you do if you were given these conflicting conditions?

Obviously, this is a contradiction, and different versions of android provide different priorities for these attributes.

I would suggest changing the EditText and Spinner attributes to:

 <EditText ... android:layout_width="0dp" ... /> <Spinner ... android:layout_width="0dp" ... /> 

And add this to your LinearLayout:

 <LinearLayout android:baselineAligned="true" ... /> 
0
source

Add android: baselineAligned = "false" for LinearLayout to view algn. This works in my project:

 <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:baselineAligned="false" android:orientation="horizontal" > <EditText android:id="@+id/text" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" /> <Spinner android:id="@+id/spinner" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" /> </LinearLayout> 
0
source

I found the following solution:

 <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="10dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical"/> <Spinner android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"/> </LinearLayout> 
0
source

All Articles