对齐在TextView中的HTML.fromHtml()中有效吗?
我试过了
<div align="center"><p>Test</p></div>以及其中的一些变体,包括在段落标签中放置不带括号的对齐制表符,但都不起作用。文本始终留在左侧。
谢谢你的帮助!
你的。
发布于 2010-10-07 01:11:40
TextView中的HTML文本不支持对齐。
发布于 2016-10-22 21:56:24
若要在textview中设置对齐方式,请首先将textview width设置为match_parent,然后在HTML标记中使用text-align选项。如下所示:
<div style="text-align: center">this text should be in center of view</div>
更新:此解决方案仅适用于android 7及更高版本:|
发布于 2014-06-14 20:40:51
虽然可以使用webview而不是TextView来对齐,并从放置在资源中的文件加载html:
public class ViewWeb extends Activity {
WebView webview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webview = (WebView) findViewById(R.id.webView1);
webview.loadUrl("file:///android_asset/index.html");
}
}https://stackoverflow.com/questions/3874999
复制相似问题