3

I have been reading posts on SO, and none of the solutions solved my problem. Im using style="@style/Base.Widget.AppCompat.Spinner.Underlined to add underline to the Spinner but for somereason the baseline of spinner is not aligning with EditText. here is my XML:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="5">

    <!-- Phone Country code Spinner -->
    <Spinner
        android:id="@+id/spProfileDetailsUser_phoneNumberCode"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        style="@style/Base.Widget.AppCompat.Spinner.Underlined"
        android:layout_gravity="bottom">
    </Spinner>

    <!--  Mobile Number Label -->
    <android.support.design.widget.TextInputLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        android:layout_weight="4">
        <EditText android:id="@+id/etProfileDetailsUser_phoneNumber"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:inputType="number"
            android:hint="Mobile Number"
            />
    </android.support.design.widget.TextInputLayout>
</LinearLayout>

Here is the result:

enter image description here

I have tried any solution I found for similar problems on SO trying to align the spinner underline with EditTxt. However, non helped. such as this post.

I am looking for solution or workaround to solve this issue.

Thanks

Poorya
  • 1,291
  • 6
  • 27
  • 57

2 Answers2

4

Just remove android:layout_marginBottom="8dp" from your TextInputLayout:

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="5"
xmlns:android="http://schemas.android.com/apk/res/android">

<!-- Phone Country code Spinner -->
<Spinner
    android:id="@+id/spProfileDetailsUser_phoneNumberCode"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    style="@style/Base.Widget.AppCompat.Spinner.Underlined"
    android:layout_gravity="bottom">
</Spinner>

<!--  Mobile Number Label -->
<android.support.design.widget.TextInputLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:layout_weight="4">
    <EditText android:id="@+id/etProfileDetailsUser_phoneNumber"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:inputType="number"
              android:hint="Mobile Number"
        />
</android.support.design.widget.TextInputLayout>

1

Get rid of

android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"

and you will be fine

Manza
  • 3,427
  • 4
  • 36
  • 57