Establecer texto en TextView utilizando Html.fromHtml

Tengo que mostrar un texto en tres partes, por lo que he utilizado Html.fromHtml como este:

txtvw.setText(Html.fromHtml("<p align=right> <b> " + "Hi!" + " </br> <font size=6>" + " How are you "+"</font> </br>" + "I am fine" + " </b> </p>")); 

El HTML es correcto, pero en el dispositivo se muestra en una línea.

Mi declaración xml de textview es:

  <RelativeLayout android:id="@+id/Home" android:layout_width="fill_parent" android:layout_height="60dp" android:background="@drawable/transparentfooter" android:layout_above="@+id/bottombar" > <TextView android:id="@+id/txt" android:layout_width="wrap_content" android:layout_height="fill_parent" android:textColor="@android:color/white"/> </RelativeLayout> 

La forma en que usó la etiqueta de Google es inapropiada. Utilice lo siguiente:

 txtvw.setText(Html.fromHtml("<p align=right> <b> " + "Hi!" + " <br/> <font size=6>" + " How are you "+"</font> <br/>" + "I am fine" + " </b> </p>")); 

Debe ser <br/> y no </br> He probado este código y muestra las 3 líneas como se esperaba.

Establecer etiquetas de líneas en el diseño android: lines = "4"

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:lines="4" android:text="@string/hello_world" tools:context=".MainActivity" /> </RelativeLayout> 

Escribir etiquetas "html" correctas

  TextView text =(TextView)findViewById(R.id.text); text .setText(Html.fromHtml("<p align=right> <b> " + "<br>" +"Hi!" + " </br> " + "<br> How are you "+" </br>" + "<br>I am fine" + " </br> </b> </p>")); 
 Html.fromHtml(String source) 

Ahora Descontinuado de Api-24.

Desde Api-24 este método cambió a

 Html.fromHtml(String source,int flags) 

Así podemos utilizar como abajo de Api 24

 txtvw.setText(Html.fromHtml("<p align=right> <b> " + "Hi!" + " <br/> <font size=6>" + " How are you "+"</font> <br/>" + "I am fine" + " </b> </p>"),Html.FROM_HTML_MODE_LEGACY); 
  • Obtener una matriz de char desde el usuario sin utilizar String
  • ¿Cómo puedo probar por Espresso android.widget.TextView setError?
  • TextView de anchura fija con compuesto estirable
  • ¿Por qué TextView.setTypeface () aumenta exageradamente mi altura TextView cuando uso la fuente Roboto-Italic.ttf?
  • android: límite de 10 caracteres por línea TextView
  • Cambiar el color de TextView que se puede hacer clic en el enfoque y hacer clic?
  • ¿Cómo hace un Android EditText (TextView) dibujar el cursor parpadeante?
  • ¿Cómo puedo añadir un TextView a un LinearLayout dinámicamente en Android?
  • Android.content.res.Resources $ NotFoundException: String resource ID Excepción grave en Main
  • Android: cómo utilizar la fuente Tamil
  • Android textview relleno entre líneas
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.