Alignment issue with TextInputLayout and Spinner

I have alignment problem with TextInputLayout and Spinner, I want Spinner to emphasize alignment with EditText underline inside TextInputLayout. This is what I do:

<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="bottom"> <android.support.design.widget.TextInputLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"> <EditText android:id="@+id/txt_discipline_code" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/lbl_input_discipline_code"/> </android.support.design.widget.TextInputLayout> <Spinner android:id="@+id/spnnr_color_discipline_register" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/Base.Widget.AppCompat.Spinner.Underlined"> </Spinner> </LinearLayout> 

But Spinner is a little lower . Can anybody help me? Thanks in advance.

EDIT:

Here is what I want: Underscore Y EditText, equal to underscore Y Spinner

Having reached this alignment, set the Spinner layout_marginBottom to 1.5dp:

 <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="bottom"> <android.support.design.widget.TextInputLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"> <EditText android:id="@+id/txt_discipline_code" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Code"/> </android.support.design.widget.TextInputLayout> <Spinner android:id="@+id/spnnr_color_discipline_register" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/Base.Widget.AppCompat.Spinner.Underlined" android:layout_marginBottom="1.5dp"> </Spinner> </LinearLayout> 

But I am afraid that this will not work properly in other devices with different sizes. Is this the only solution?

+7
android android-layout android-spinner android-textinputlayout
source share
1 answer

From what you mentioned, you want to achieve this result:

enter image description here

use this code:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="bottom" xmlns:android="http://schemas.android.com/apk/res/android" android:baselineAligned="false"> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" app:srcCompat="@drawable/ic_launcher" android:id="@+id/imageView" android:padding="10dp" android:layout_weight="5" /> <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <EditText android:id="@+id/name_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.5" android:hint="Name"/> </android.support.design.widget.TextInputLayout> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" app:srcCompat="@drawable/ic_launcher" android:id="@+id/imageView1" android:padding="10dp" android:layout_weight="1.1" /> <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="-12dp" android:layout_marginStart="-12dp" android:layout_weight="0.6"> <EditText android:id="@+id/code_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Code"/> </android.support.design.widget.TextInputLayout> <Spinner android:id="@+id/spnnr_color_discipline_register" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="wrap_content"/> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" app:srcCompat="@drawable/ic_launcher" android:id="@+id/imageView2" android:padding="10dp" android:layout_weight="5" /> <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <EditText android:id="@+id/foo_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.5" android:hint="Foo"/> </android.support.design.widget.TextInputLayout> </LinearLayout> </LinearLayout> 

Hope this helps !!!

+2
source share

All Articles