![](/img/trans.png)
[英]Android: How to remove end blank space from Textview with marquee
[英]How to add space between words of paragraph to remove space from end in Textview(i.e. Justify Text) in Android?
我正在為我的應用程序創建一個 UI,我需要在其中顯示這樣的段落
為此,我像這樣使用Textview
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp24"
android:fontFamily="sans-serif-thin"
android:text="@string/sample_description"
android:textColor="@color/black"
android:lineSpacingExtra="@dimen/dp4"
/>
但是我的output是這樣的
如果您注意到我的 output 在某些行的末尾還有一些空間。 我不想要它。
如果您在第一張圖片中看到最后沒有剩余空間。 他們在單詞之間添加了空格以從末尾刪除空格。
所以,我的問題是如何實現第一張圖片 output?
你需要的東西叫做合理的內容。 您可以使用
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:justificationMode="inter_word" />
如果您使用 Android 8+,您可以使用
android:justificationMode="inter_word".
作為替代方案,您可以使用WebView
將文本放入 HTML 格式:
<string name="sporttext">
<![CDATA[
<html>
<head></head>
<body style="text-align:justify;color:gray;background-color:white;">
This sport shirt is crafted from scratch ...
</body>
</html>
]]>
</string>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.