android webview blinking once when loading data

别说谁变了你拦得住时间么 提交于 2020-01-02 04:57:12

问题


I have text preloaded in a webview. When the data from the internet comes, I reload the webview with the new data.

The problem is the screen blinks once during the load data transition.

Any advice?


回答1:


Try to disable the hardware accelerator on the activity:

android:hardwareAccelerated="false"



回答2:


In your Activity

    LinearLayout.LayoutParams dfparams = new LinearLayout.LayoutParams(0,0, 0);
    wedview.setLayoutParams(dfparams);
    wedview.loadDataWithBaseURL(URL_SERVER, content, "text/html", "utf-8", null);

    wedview.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0);
            wedview.setLayoutParams(params);

        }
    });

In Your layout.xml

    <LinearLayout
        android:id="@+id/llSearch"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@null"
        android:orientation="vertical" >
    <WebView
            android:id="@+id/wvContent"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:scrollbars="none" />
 </LinearLayout>


来源:https://stackoverflow.com/questions/14322122/android-webview-blinking-once-when-loading-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!