2012-09-21 11 views
48
Expand

Hier ist mein Layout:Wie man Höhe EditText Box

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

    <EditText 
     android:id="@+id/etTweetReview" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="10dp" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:ems="10" 
     android:hint="Discuss up to 140 characters" 
     android:imeOptions="actionDone" 
     android:inputType="textCapSentences" 
     android:lines="2" 
     android:maxLength="140" 
     android:paddingBottom="10dp" 
     android:singleLine="false" /> 

    <Button 
     android:id="@+id/theReviewBarButton" 
     android:layout_width="200dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginBottom="5dp" 
     android:text="Submit Review" 
     android:textSize="22sp" /> 

    <Spinner 
     android:id="@+id/spinnerSort" 
     android:layout_width="120dp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" /> 

    <ListView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/android:list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginLeft="5dp" 
     android:scrollbars="none" 
     android:layout_marginRight="5dp" 
     android:layout_marginTop="8dp" > 
    </ListView> 

</LinearLayout> 

Wenn das EditText Box bis zum Ende kommt, will ich es in der nächsten Zeile umbrochen. Im Moment läuft es einfach weiter und verschiebt alles vom Bildschirm weg.

+1

Mögliches Duplikat von [Android Word-Wrap EditText-Text] (http://stackoverflow.com/questions/3276380/android-word-wrap-edittext-text) – blahdiblah

Antwort

97

Bereits zuvor gefragt und beantwortet.

Android Word-Wrap EditText text

Beispiel XML-Code:

<EditText 
    android:id="@+id/edtInput" 
    android:layout_width="0dip" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:hint="@string/compose_hint" 
    android:inputType="textCapSentences|textMultiLine" 
    android:maxLength="2000" 
    android:maxLines="4" /> 
+7

Ich sah mir andere Antworten an, vermisste aber das Größte: 'textMultiLine' danke, Markierung richtig. – KickingLettuce

+0

android: layout_height = "wrap_content" android: inputType = "textCapSentences | textMultiLine" das macht Arbeit –

+0

Großes Attribut, das mir nicht bekannt ist. Denken Sie daran, die Maxlines dynamisch basierend auf der Anzahl der Strings zu aktualisieren. –

25

Angenommen, Sie es nur auf den ersten eine Zeile haben wollen dann zu 5 Zeilen erweitern und Sie wollen maximal 10 Zeilen haben.

<EditText 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:id="@+id/etMessageBox" 
        android:layout_alignParentLeft="true" 
        android:layout_centerVertical="true" 
        android:autoLink="all" 
        android:hint="@string/message_edit_text_hint" 
        android:lines="5" 
        android:minLines="1" 
        android:gravity="top|left" 
        android:maxLines="10" 
        android:scrollbars="none" 
        android:inputType="textMultiLine|textCapSentences"/> 

Durch android:lines Erhöhung können Sie es definieren erweitern, wie viele Zeilen.

+0

Was ist, wenn wir mit 4 Zeilen beginnen und den Text nach oben scrollen lassen, wenn der Benutzer mehr als 4 Zeilen Text eingegeben hat? – Ivan

3

versuchen diesen Code

<EditText 
    android:id="@+id/"edittext01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:inputType="textCapSentences|textMultiLine" 
    android:maxLength="100" 
    android:maxLines="10"/> 
+1

Es wäre wirklich gut, wenn Sie einen Kommentar hinzufügen könnten, um dieser Antwort einen Kontext hinzuzufügen. –

0

Entfernen Sie diese Zeile bilden Ihre EditText

android:inputType="textCapSentences" 

und fügen Sie diese Zeile mit der Anzahl der Zeilen von Ihnen gewünschten

android:lines="2" 

Hoffnung, dies hilft Ihnen

3

Fügen Sie einfach android: lines = "6" auf Ihre EditText

<Edittext 
     android:id="@+id/edt_address" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:inputType="textMultiLine" 
     android:maxLines="6"    
     android:lines="6" 
     android:layout_marginTop="@dimen/activity_vertical_margin" 
     android:gravity="left"/> 
0

Sie benötigen EditText Höhe auf android:layout_height="wrap_content"

&

android:lines="5" 

Dies hat den Trick für mich in ConstraintLayout

Verwandte Themen