I am having trouble displaying long text on my webview.
My width of webview is set to 400dp.
I want my long text: ex. “looooooooooooooooooooooooooooooooonnnggg!!!”
to display in multiple lines so that users don’t have to scroll left/right nor text gets truncated.
However, I only get following result:

How can this long text be display in multiple lines?
My expected result:
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>
Java
@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", "");
}
Your problem isn’t specific to WebView. This is how all browsers render text without whitespace in it. If you want the text to wrap, you will either need to put whitespace in, or write some javascript to process it and wrap it that way, or, alternatively, just wrap it before you feed it to the WebView.