If I add spinner in a horizontal LinearLayout or in a table row for example like this:
<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>
The spinner floats down. It floats down 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 way to make it align with the other Views like the EditText on android 2.3.
By floats down I mean:
***********************
* if EditText is here * ************************
*********************** * Spinner will be here *
************************
Old post, but it may help :
setting baselineAligned to true is unecessary as it's its default value (explains here : http://developer.android.com/reference/android/widget/LinearLayout.html#attr_android:baselinealigned)
I've fixed it by hardcoding a height to both textview and spinner, and setting baselineAligned to FALSE.
Spinner is smaller than EditText, so a way to align both it's to add android:layout_height="match_parent" to Spinner, and keep LinearLayout and EditText with wrap_content.
I faced the same trouble before and I figured out 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
of your LinearLayout
to bottom
and will solve your problem.
You should add the following to your editText:
android:layout_gravity="center_vertical"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With