2016-10-27 7 views
1

Ich benutze EditTexts in TextInputLayouts für die Implementierung einiger Eingabefelder. Mein Problem ist, dass am Ende von EditTexts etwas mehr Platz ist, was offensichtlich ist, wenn ich mehrere Eingabefelder untereinander platziere.Android: Entfernen Sie zusätzlichen Platz am Ende von EditText

Hier ist ein Bild von dem, was ich sehe, mit der Lücke zwischen den Eingabefeldern sichtbar (umrahmt mit rot).

enter image description here

Ich möchte diesen zusätzlichen Platz loszuwerden. Das Setzen von Paddings und Margen auf 0 hat nicht geholfen und obwohl ich weiß, dass ich negative Ränder anwenden kann, möchte ich diese Lösung wirklich vermeiden, da sie einige Probleme mit UI-Tests verursacht hat. Hat jemand eine bessere Idee, wie man diesen Extraraum beseitigt?

Einige Codes:

Stylings für den EditText und der TextInputLayout (beachten Sie, dass die Standard-Rand Bemaßungswerte alle 0DP sind):

<style name="EditTextLayout"> 
    <item name="android:layout_height">@dimen/input_field_height</item> 
    <item name="android:minHeight">@dimen/input_field_height</item> 
    <item name="android:background">@drawable/input_field_background</item> 
    <item name="android:paddingBottom">@dimen/default_margin_bottom</item> 
    <item name="android:paddingStart">@dimen/default_margin_left</item> 
    <item name="android:paddingEnd">@dimen/default_margin_right</item> 
    <item name="android:paddingTop">@dimen/default_padding_top</item> 
    <item name="android:layout_marginBottom">@dimen/default_margin_bottom</item> 
    <item name="android:textColorHint">@color/input_field_floating_label</item> 
</style> 

<style name="EditTextTheme"> 
    <item name="android:imeOptions">actionDone</item> 
    <item name="android:maxLines">1</item> 
    <item name="colorControlNormal">@color/primary_line_color</item> 
    <item name="colorControlActivated">@color/nordea_blue</item> 
    <item name="colorControlHighlight">@color/error_color</item> 
    <item name="android:textColorPrimary">@color/input_field_text</item> 
    <item name="android:textSize">@dimen/textsize_caption</item> 
    <item name="android:textColorHint">@color/input_field_floating_label</item> 
</style> 

<style name="EditText"> 
    <item name="android:theme">@style/EditTextTheme</item> 
    <item name="android:textCursorDrawable">@drawable/cursor_blue</item> 
    <item name="android:paddingStart">@dimen/default_padding</item> 
    <item name="android:paddingEnd">@dimen/default_padding</item> 
    <item name="android:paddingTop">@dimen/input_field_floating_label_padding</item> 
    <item name="android:layout_marginBottom">@dimen/default_margin_bottom</item> 
    <item name="android:background">@drawable/input_field_divider</item> 
</style> 

Hintergrund für die EditText (hergestellt nur in der unteren Zeile zu machen dicker):

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape android:shape="rectangle"> 
      <solid android:color="@android:color/transparent"/> 
     </shape> 
    </item> 
    <item 
     android:left="@dimen/input_field_background_side_margin" 
     android:right="@dimen/input_field_background_side_margin" 
     android:top="@dimen/input_field_background_side_margin"> 
     <shape> 
      <solid android:color="@android:color/transparent"/> 
      <stroke 
       android:width="@dimen/input_field_divider_height" 
       android:color="@color/input_field_divider_color"></stroke> 
      <padding 
       android:bottom="@dimen/testlogin_dropdown_divider_padding" 
       android:top="@dimen/input_field_floating_label_padding"/> 
     </shape> 
    </item> 
</layer-list> 

Hintergrund für die TextInputLayout:

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:bottom="@dimen/inputfield_background_light_margin_bottom"> 
     <shape android:shape="rectangle"> 
      <solid android:color="@color/input_field_layout_bg"/> 
      <padding 
       android:bottom="0dp" 
       android:left="0dp" 
       android:right="0dp" /> 
     </shape> 
    </item> 
</layer-list> 

Verbrauch:

<android.support.design.widget.TextInputLayout 
    android:id="@+id/input_container" 
    style="@style/EditTextLayout" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/input_field_height" 
    app:errorTextAppearance="@style/EditTextErrorText" 
    app:hintTextAppearance="@style/EditTextFloatingLabel" 
    tools:hint="Hint text" 
    tools:text="Label text"> 

    <android.support.design.widget.TextInputEditText 
     android:id="@+id/input_editfield" 
     style="@style/EditText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:imeOptions="actionDone" 
     android:inputType="text|textCapSentences"/> 

</android.support.design.widget.TextInputLayout> 
+0

Haben Sie versucht, vollständig removig 'padding' und' marginBottom' ? Also, was ist der Punkt in so vielen 0dp 'Paddings'? – NightSkyLove

+0

Ich bin mir nicht sicher, können Sie versuchen, die Werte von testlogin_dropdown_divider_padding und input_field_floating_label_padding als Testfall zu ändern? – Raghavendra

+0

@Prad, habe ich alle diese versucht, die Polsterungen und die Ränder zu entfernen, die Werte usw. ändern. Was auch immer ich mache, gibt es immer diesen zusätzlichen Platz an der Unterseite. Auch wenn ich versuche, die Paddings und Ränder auf 0 zu setzen, erscheint es immer noch. Ich frage mich, ob jemand weiß, woher genau dieser Raum kommt und was ich tun kann, um ihn los zu werden. Wie ich bereits sagte, negative Margen sind keine gute Lösung für mich, also suche ich nach Alternativen. – hildegard

Antwort

0

versuchen, diese

android:layout_marginTop="-10dp" 

für Ihren 2. Bearbeiten von Text, verwenden Sie den Wert nach Ihren convinience

Verwandte Themen