Android 如何在 textview 中的文本之间留出空间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24552233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I give space in between text in textview?
提问by Steve
I need to make something like this according to Android screen bound,
我需要根据Android屏幕绑定做这样的事情,
S M T W T F S
I am doing like this:
我这样做:
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:text="S M T W T F S" />
This is not working properly, not according to device screen bound. I need something like this:
这不能正常工作,不是根据设备屏幕绑定。我需要这样的东西:
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:text="S""10dp""M""10dp""T""10dp""W""10dp""T""10dp""F""10dp""S""10dp" />
回答by App Kart
We can use it.
我们可以使用它。
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="A B     C"/>
回答by Gaganpreet kaur
Use the letterSpacing
attribute for spacing between letters:
使用letterSpacing
属性表示字母之间的间距:
android:id="@+id/txt_work"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:typeface="serif"
android:layout_below="@+id/txt_wecm"
android:layout_marginLeft="20dp"
android:textSize="32dp"
android:letterSpacing="0.1"
android:textColor="#fff"
android:text="World"
回答by MilapTank
USE Unicode Character NO-BREAK SPACETextView
support this
USE Unicode Character NO-BREAK SPACETextView
支持这个
try this
尝试这个
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:text="@string/days" />
put this in String.xml
把它放在 String.xml 中
<string name="days">S\u00A0M\u00A0T\u00A0W\u00A0T\u00A0F\u00A0S</string>
EDIT 1
编辑 1
it is fulfill your requirement but not efficient way till you not find solution with one TextView
you can try like this
它可以满足您的要求,但不是有效的方法,直到您找不到TextView
可以像这样尝试的解决方案
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="S" />
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="M"
android:textAlignment="center" />
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="T" />
<TextView
android:id="@+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="W" />
<TextView
android:id="@+id/textView5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="T" />
<TextView
android:id="@+id/textView6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="F" />
<TextView
android:id="@+id/textView7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="S" />
回答by My God
Letter-spacing in the TextView -
TextView 中的字母间距 -
android:textScaleX
Sets the horizontal scaling factor for the text.
Must be a floating point value, such as "1.2".
android:textScaleX
设置文本的水平比例因子。
必须是浮点值,例如“1.2”。
You can increase the scaling factor depending upon the scale that you need between letters.
您可以根据字母之间所需的比例增加比例因子。
Android docs for android:textScaleX.
android:textScaleX 的Android 文档。
回答by chanu panwar
If you want some space between Text in textView, you can use android:lineSpacingExtra="10dp"
如果你想在 textView 中的 Text 之间留一些空间,你可以使用 android:lineSpacingExtra="10dp"
you can try like that:-
你可以这样尝试:-
<TextView
android:layout_width="match_parent"
android:layout_height="180dp"
android:lineSpacingExtra="10dp"
android:text="hi
hello"/>
回答by JaKoZo
textView.setText(Html.fromHtml("<span style=letter-spacing:10px>TEXT</span> "));
But i dont if this works
但我不知道这是否有效