關於文本兩端對齊的問題,可以參考如下:
To justify text in android I used WebView
- setContentView(R.layout.main);
- WebView view = new WebView(this);
- view.setVerticalScrollBarEnabled(false);
- ((LinearLayout)findViewById(R.id.inset_web_view)).addView(view);
- view.loadData(getString(R.string.hello), "text/html", "utf-8");
and html
- <string name="hello">
- <![CDATA[
- <html>
- <head></head>
- <body style="text-align:justify;color:gray;background-color:black;">
- Lorem ipsum dolor sit amet, consectetur
- adipiscing elit. Nunc pellentesque, urna
- nec hendrerit pellentesque, risus massa
- </body>
- </html>
- ]]>
- </string>
I can't yet upload p_w_picpaths to prove it but "it works for me".
主要思路:使用WebView來加載,用css來實現兩端對齊。
注意:webview要設置成透明的,還有加載時使用
myWebView.loadDataWithBaseURL("", getString(R.string.desc), "text/html", "utf-8",""); 這個方法
// myWebView.loadData(getString(R.string.desc), "text/html", "utf-8"); // 這個方法遇到一些字符中會亂碼