如何使TextView两端对齐?有没有解决方法?我在大部分论坛中搜索了,但是没有找到答案。请帮助我。
我们创建了一个简单的类来实现这个功能。目前有两种方法可以达到您想要的效果。两种方法都无需WEBVIEW并且支持SPANABLES。
库: https://github.com/bluejamesbond/TextJustify-Android
支持: Android 2.0 至 5.X
设置
// Please visit Github for latest setup instructions.
截图
很抱歉,Android不支持文本对齐。您可以使用android:gravity
属性将文本左对齐、右对齐或居中等,但无法实现文本对齐。我想唯一的选择是使用WebView
显示文本,然后使用CSS对文本进行对齐。
<RelativeLayout android:id="@+id/RelativeLayout01"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<TextView android:id="@+id/TextView2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="I'm TextView- Left" android:layout_alignParentLeft="true">
</TextView>
<TextView android:id="@+id/TextView1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="I'm TextView- Right" android:layout_alignParentRight="true">
</TextView>
</RelativeLayout>
截图: