您的位置:首页 > 移动开发 > Android开发

Android开发:文本实现两端对齐

2012-09-14 14:03 363 查看
关于文本两端对齐的问题,可以参考如下:

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 images 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"); // 这个方法遇到一些字符中会乱码

本文出自 “Pain past is pleasure” 博客,请务必保留此出处http://emilyzhou.blog.51cto.com/3632647/990713
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: