2015-11-19 3 views
2

Я использовал TextInputLayout для EditText, и рядом с ним есть TextView. Я вижу, что между TextInputLayout и TextView есть дополнительное пространство. Я хочу удалить лишнее пространство. Фотографии прилагаются с TextInputLayout и без него. Я включил границы в вариантах разработчика, поэтому pic может выглядеть запутанным, но информативным.Дополнительное пространство между TextInputLayout и TextView

Ниже раскладка:

<?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

ответ

0

Похоже, это не дополнительное пространство , а только нижнюю часть виджета TextInputLayout. У меня нет фонового ресурса, но по сути это ваш код выглядит на моем устройстве. Вы можете попробовать EditText, не помещая его внутри виджета TextInputLayout, если хотите, и тогда у вас не будет дополнительного места внизу или сверху.

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" /> 

0

Попробуйте андроида: layout_alignStart = "@ ID/layoutCurrentPW"

3

Существует известная проблема с TextInputLayout, который отображает дополнительные отступы когда отображается сообщение об ошибке и не удаляется, когда очищается ошибка или вызывается setErrorEnabled (false).

https://code.google.com/p/android/issues/detail?id=200137

Обойти эту проблему можно вручную скрыть нижнее расположение ребенка, когда очищаются ошибка:

textInputLayout.setError(null); 
if (textInputLayout.getChildCount() == 2) 
    textInputLayout.getChildAt(1).setVisibility(View.GONE); 
+0

хорошей информации. +1 – cgr

Смежные вопросы