Search code examples
androidtextviewandroid-textinputlayout

Extra space between TextInputLayout and TextView


I have used TextInputLayout to an EditText and there is a TextView just below to it. I see there is an extra space between TextInputLayout and TextView. I want to remove that extra space. Pics attached with and without TextInputLayout. I have enabled boundaries in developer options so pic may look confusing but informative.

Below is the layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.design.widget.TextInputLayout
        android:id="@+id/layoutCurrentPW"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        app:errorEnabled="true">

        <EditText
            android:id="@+id/editTextCurrentPassword"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginLeft="50dp"
            android:layout_marginRight="50dp"
            android:layout_marginTop="30dp"
            android:background="@drawable/edit_text_border_drawable"
            android:gravity="center"
            android:hint="@string/current_password"
            android:layout_gravity="bottom"
            android:inputType="textPassword"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/black" />
    </android.support.design.widget.TextInputLayout>

    <TextView
        android:id="@+id/textForgotPassword"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:clickable="true"
        android:text="@string/forgot_password"
        android:textSize="17sp" />
</LinearLayout>

without textInputLayout

With TextInputLayout


Solution

  • Looks like this is not extra space, but just the bottom half of the TextInputLayout widget. I don't have your background resource, but this is essentially what your code looks like on my device. You could try the EditText without putting it inside a TextInputLayout widget if you want, and then you wouldn't have the extra space on the bottom or top.

    how your code looks on my device

    <?xml version="1.0" encoding="utf-8"?>
    

    <android.support.design.widget.TextInputLayout
        android:id="@+id/layoutCurrentPW"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:background="@android:color/holo_green_light"
        app:errorEnabled="true">
    
        <EditText
            android:id="@+id/editTextCurrentPassword"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginLeft="50dp"
            android:layout_marginRight="50dp"
            android:layout_marginTop="30dp"
            android:gravity="center"
            android:background="@android:color/white"
            android:text="current_password"
            android:layout_gravity="bottom"
            android:inputType="textPassword"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/black" />
    </android.support.design.widget.TextInputLayout>
    
    <TextView
        android:id="@+id/textForgotPassword"
    
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:clickable="true"
        android:text="forgot_password"
        android:textSize="17sp" />