要实现Android两端对齐的文字排版效果一个更简单的方式就是使用WebView,利用HTML样式来实现。
首先定义一个String常量,我们可以将它视为一个HTML模板:
private static final String WEBVIEW_CONTENT = "<html><head></head><body style=\"text-align:justify;margin:0;\">%s</body></html>";接下来在Layout文件中定义WebView:<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent" />最后在Activity中:WebView webView = (WebView)findViewById(R.id.webview);
webView.setVerticalScrollBarEnabled(false);
webView.loadData(String.format(WEBVIEW_CONTENT, yourContent, "text/html", "utf-8");版权声明:本文为u010461658原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。