2016-07-13 8 views
0

derzeit ich dieses Ergebnis für eine mehrzeiliges Textansicht bin immer -Textview neue Zeile (in mehrzeiligen) gibt

maxLines = 2 

Wenn Text ist -

Hallo

hfhfhfhfhfhfhhfhfhfhfhfhhfhfhf

Dann Ausgang ist:

enter image description here

Aber ich brauche es wie folgt aus:

enter image description here

Bitte mir helfen, dieses Ergebnis zu erhalten :)

XML ist

<TextView 
      android:id="@+id/user_name" 
      style="@style/default_text_font_face" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:ellipsize="end" 
      android:scrollHorizontally="true" 
      android:maxLines="2" 
      android:text="Hello hffffffhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhhfhfhhfhfhfhfhhfhfhfhhfhfhfhfhhfhfhfhfhhfhfhfhfhhfhfhfhfhhfhf" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="@color/white" /> 
+2

Verwenden hilft Hallo hhhhhhhhhhhhh \ nhhhhhhhhhhhhhhh ... –

+1

Was ist die Frage? – Li357

+0

@NehaK siehe meine Antwort unten. – Ironman

Antwort

0

Sie bei Temperaturen unter Eigenschaft haben ..

android:maxWidth="size" 

Ersetzen Sie die size durch die von Ihnen bevorzugte Größe. Zum Beispiel 100dip.

UpDate:

XML-Datei

<TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:maxLines="2" 
     android:maxWidth="50dip" 
     android:text="Best Efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textSize="15dp" /> 

Ausgang:

enter image description here

UpDate 2:

unter Verwendung von .

<TextView 
      android:id="@+id/textView2" 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:maxLines="2" 
      android:maxWidth="50dip" 
      android:text="Best Efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textSize="15dp" /> 

Ausgang:

enter image description here

+0

Ich habe getestet und es löst nicht das Problem –

+0

@ PhanVănLinh Es ist Arbeit sehe meine Update-Antwort. – Ironman

+0

mit Ihrem Code und ich es in Nexus4 Vorschau testen, ist das Ergebnis anders –

1

Verwenden

android:layout_width="match_parent" 

zu Ihrem TextView

EDIT1

Versuchen Sie, die folgende Art und Weise

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#535353" 
    android:textColor="#ffffff" 
    android:maxLines="2" 
    android:text="Best Effffffffffffffffffffffffffffffff\nfffffffffffffffffffffffffffffffffffffff" 
    android:textSize="20dp"/> 

</LinearLayout> 

Ausgabe

answer

Ich hoffe, das Ihnen wird