When using WebView to display plain formatted text (without downloading remote content), some devices, such as Nexus 4 or Galaxy Nexus, have a very noticeable delay between onPageFinished () and the actual display of the text. If WebView is used in a dynamic vertical layout with the height set to wrap_content, all the elements below will jump noticeably and, therefore, create a very bad user experience.
For instance:
public class WebViewActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_web_view); WebView webview = (WebView) findViewById(R.id.webview); webview.loadData("<html><head></head><body>WebView rendering is slow on some devices like the Nexus 4!</body></html>", "text/html", "utf-8"); } }
With R.layout.activity_web_view will be
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#AAA" > <WebView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/webview"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="20sp" android:layout_margin="5dp" android:text="Elements below the WebView are jumping down when rendering is completed."/> </LinearLayout>
A demo project with this code can be found at https://github.com/rodja/webview-slow-rendering-demo
What is the best way around this problem? Speed Up Tips I found in StackOverflow doesn't seem to help. Hides the entire LayoutGroup until rendering is done , just an option?
source share