WebView で長いテキストを表示するのに問題があります。webview の幅は 400dp に設定されています。長いテキストが欲しい: ex. 「おおおおおおおおおおおおおおおおお!!!」ユーザーが左右にスクロールする必要がなく、テキストが切り捨てられないように、複数行で表示します。
ただし、次の結果しか得られません。
この長いテキストを複数行で表示するにはどうすればよいですか?
私の期待される結果:
Hello World
looooooooooooooooooooooooooooooooooooo
ooooooooooooooooooooonnnngg!!!
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<WebView
android:id="@+id/webview"
android:layout_width="400dp"
android:layout_height="fill_parent"
/>
</LinearLayout>
ジャワ
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
String html = "<html><head></head><body>Hello World<br>looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooonnnggg!!!</body></html>";
webview.loadDataWithBaseURL(
"http://nada", html, "text/html", "utf8", "");
}