0

如何在 textview setText 选项中对齐段落?我正在从 API 加载数据,并且需要合理地显示段落。

textv.setText(Html.fromHtml(文本)); 我在适配器下面尝试过,但没有任何效果 text = text + ""+paragrph +"

";

除了 webview 之外还有其他可能吗?

4

2 回答 2

0

您需要使用 WebView 来对齐文本。这是一个例子:

    WebView webView = (WebView) findViewById(R.id.webView);
    webView .setBackgroundColor(Color.TRANSPARENT);
    String header = "<html><head><style type=\"text/css\">@font-face {font-family: MyFont;src: url(\"file:///android_asset/fonts/Walkway-Ultrabold.ttf\")}body {font-family: MyFont;font-size: medium;text-align: justify;}</style></head><body>";
    String footer = "</body></html>";
    String text_web_view = header + message + footer;
    webView.loadDataWithBaseURL(null, text_web_view, "text/html", "UTF-8", null);

此代码集还放置了一个字体到 assets/fonts 文件夹中。

于 2016-11-16T15:45:17.860 回答
0

您不能在 TextView 中设置像重力这样的属性。您可以使用 WebView 或其他开源库。Android 尚不支持文本对齐。

于 2016-11-16T15:17:28.783 回答