實現跑馬燈效果的TextView
只需要在佈局文件中加上屬性
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
如下
<TextView
android:id="@+id/txtOne"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="你整天說着日了狗日了狗,但是你卻沒有來,呵呵呵呵呵呵呵呵呵呵~"/>
設置TextView字間距和行間距
字間距:
android:textScaleX:控制字體水平方向的縮放,默認值1.0f,值是float
Java中setScaleX(2.0f);
行間距:
android:lineSpacingExtra:設置行間距,如"3dp" android:lineSpacingMultiplier:設置行間距的倍數,如"1.2"
Java代碼中可以通過: setLineSpacing方法來設置
自動換行
自動換行通過 android:singleLine 設置,默認爲 false。
如需要自動換行,可以用:
android:singleLine = "false"
如果要在一行顯示完,不換行,可以用:
android:singleLine = "true"
多行顯示不完,使用maxLines屬性