Espaciado de línea individual para cada línea
¿Es posible definir TextView
línea individuales para cada línea de texto de un TextView
?
Ejemplo:
- ¿Cómo hago el centro vertical de dos puntos en TextView
- Android textview settext mostrar nullpointer excepción
- Fundido de fondo de un android de vista de texto
- TextView envuelve el texto después de cambiar el tipo de letra
- Recortar TextView en el centro, reservando caracteres finales
TextView tv = new TextView(context); tv.setText("line1\nline2\nline3");
El método setLineSpacing(float add, float mult)
define los espaciados de línea para todas las líneas de texto de TextView
. Me gustaría definir otro espaciado de línea entre line1 y line2 y un espaciado de línea diferente entre line2 y line3.
Alguna idea de como hacer esto ?
¿Un spannable proporciona una solución?
- Android sdk 18 La gravedad de TextView no funciona verticalmente
- ¿Existe tal llamada de método "getBackgroundColor"?
- Palabra que se puede hacer clic en TextView en android
- Obtener el texto visible actual en la vista de texto
- TextView: lineSpacingMultiplier y lineSpacingExtra también se aplica a la última línea
- Excepción de Android TextView y puntero nulo
- Ellipsize de TextView no funciona en maxLines = 1
- Escribe un párrafo con textview en Android
Sí, puede hacerlo utilizando la interfaz LineHeightSpan
. Aquí hay un código de muestra rápido y sucio sobre cómo hacer esto:
public class MyActivity extends Activity { private static class MySpan implements LineHeightSpan { private final int height; MySpan(int height) { this.height = height; } @Override public void chooseHeight(CharSequence text, int start, int end, int spanstartv, int v, FontMetricsInt fm) { fm.bottom += height; fm.descent += height; } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final TextView tv = new TextView(this); setContentView(tv); tv.setText("Lines:\n", BufferType.EDITABLE); appendLine(tv.getEditableText(), "Line 1 = 40\n", 40); appendLine(tv.getEditableText(), "Line 2 = 30\n", 30); appendLine(tv.getEditableText(), "Line 3 = 20\n", 20); appendLine(tv.getEditableText(), "Line 4 = 10\n", 10); } private void appendLine(Editable text, String string, int height) { final int start = text.length(); text.append(string); final int end = text.length(); text.setSpan(new MySpan(height), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } }
Usted puede hacer este tipo de estilos específicos a la textview usando Html. Pruebe este ejemplo,
tv.setText(Html.fromHtml("<h2>Text1</h2><br><p>Text2</p>"));
Diferentes tipos de etiquetas permitidas aquí son,
<a href="..."> <b> <big> <blockquote> <br> <cite> <dfn> <div align="..."> <em> <font size="..." color="..." face="..."> <h1> <h2> <h3> <h4> <h5> <h6> <i> <img src="..."> <p> <small> <strike> <strong> <sub> <sup> <tt> <u>
No es posible. Esta técnica se utiliza en c, c ++. Lo que se usa dentro de setText (), muestra todo el texto que se escribe.
Prueba esto:
android:lineSpacingMultiplier = "3"
El espaciado de línea también puede estar en formato decimal.
- RegisterReceiver for Broadcast sólo si no está ya registrado?
- Quitar espacio adicional alrededor de GridView programaticamente