2016-06-25 7 views
3

Ich habe eine Texteingabe mit Hilfe der Design-Support-Bibliothek erstellt, aber es verhält sich merkwürdig innerhalb der Constraint-Layout Ich legte den Code unten, wie ich das Widget wünschen angezeigt werden und es wird zunächst sowohl im Design-Builder als auch auf dem Gerät korrekt angezeigt. Wenn ich jedoch TextInputLayout (entweder im Entwurfs- oder im Blueprint-Layout) wähle, hat die EditText ihre layout_width von zu 0dp geändert, was dazu führt, dass sie verschwindet.Layout-Problem mit TextInputLayout als Teil von Constraint-Layout

<android.support.design.widget.TextInputLayout 
    android:id="@+id/textInputLayout" 
    android:layout_height="wrap_content" 
    android:layout_width="0dp" 
    app:layout_constraintLeft_toLeftOf="@+id/activity_login" 
    android:layout_marginLeft="16dp" 
    android:layout_marginStart="16dp" 
    app:layout_constraintTop_toTopOf="@+id/activity_login" 
    android:layout_marginTop="16dp" 
    app:layout_constraintRight_toRightOf="@+id/activity_login" 
    android:layout_marginRight="16dp" 
    android:layout_marginEnd="16dp" 
    app:layout_constraintBottom_toBottomOf="@+id/activity_login" 
    android:layout_marginBottom="16dp"> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:inputType="textEmailAddress" 
     android:ems="10" 
     android:id="@+id/email" 
     android:layout_weight="1" 
     android:hint="@string/email" 
     tools:layout_editor_absoluteX="0dp" 
     tools:layout_editor_absoluteY="11dp"/> 
</android.support.design.widget.TextInputLayout> 

The state of the layout after the EditText have changed

+1

Was ist dann dein Problem? Scheint so, als ob das richtig funktioniert. –

+0

Leider ist es nicht. Die Eigenschaft layout_width EditText wird weiterhin auf "0dp" gesetzt. Dies tritt jedes Mal auf, wenn eine gleichgeordnete oder übergeordnete Ansicht bearbeitet wird. –

+0

Ja, das ist das genaue Verhalten. Die 'EditText'-Breite wird derzeit als' match_parent' festgelegt. Wann immer eine Änderung am Elternlayout den 'EditText' in ihm beeinflussen sollte. –

Antwort

2

Ich dachte, ich zurückkommen würde und eine Lösung bieten, da diese nach wie vor offen gelassen wird.

Der Grund, warum ich sah, dass die EditText-Ansichten sich im TextInputLayout unnormal verhielten, liegt daran, dass sie nicht an erster Stelle stehen sollten. Der TextInputLayout ist Teil der Design-Support-Bibliothek und bietet Entwicklern eine einfache Möglichkeit, dynamische Beschriftungen und Fehlermeldungen für Textfelder auf eine Weise zu erstellen, die mit der Material-Design-Spezifikation konsistent ist. Sie haben jedoch einen TextInputEditText als Kind, nicht EditText.

<android.support.design.widget.TextInputLayout 
    android:id="@+id/emailLayout" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:labelFor="@+id/email" 
    app:layout_constraintLeft_toLeftOf="@+id/activity_login" 
    android:layout_marginLeft="16dp" 
    android:layout_marginStart="16dp" 
    app:layout_constraintTop_toTopOf="@+id/activity_login" 
    android:layout_marginTop="16dp" 
    app:layout_constraintRight_toRightOf="@+id/activity_login" 
    android:layout_marginRight="16dp" 
    android:layout_marginEnd="16dp" 
    app:layout_constraintBottom_toBottomOf="@+id/activity_login" 
    android:layout_marginBottom="16dp"> 

    <android.support.design.widget.TextInputEditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/email" 
     android:inputType="textEmailAddress" 
     android:hint="@string/email" 
     tools:layout_editor_absoluteX="0dp" 
     tools:layout_editor_absoluteY="11dp" 
     /> 
</android.support.design.widget.TextInputLayout> 
+0

Es ist wirklich ärgerlich, dass wir im Android Studio, wenn wir das TextInputLayout ziehen, EditText hinein bekommen, aber nach [Documentation] (https://developer.android.com/reference/android/support/design/widget/TextInputLayout.html) könnte man sehen, dass sie android.support.design.widget.TextInputEditText anstelle von EditText unterstützen – Pulkit

Verwandte Themen