4

In web view when I scroll the page little bit down then it scroll up automatically on some pages not all pages but on some pages.Why this happen and what is it solution Here is xml code

<android.support.design.widget.CoordinatorLayout android:id="@+id/nonVideoLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    >
<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipeContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    >
    <WebView
        android:id="@+id/webView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         />
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>

Here is my code you can check this

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_view);
        bindLayout();
        mySwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                webView.reload();
            }
        });
        CookieManager.getInstance().setCookie(url, cookie);
        webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setUseWideViewPort(true);
        ProgressDialogHelper.showProgress(WebViewActivity.this);
        webView.setWebViewClient(new WebViewClient(){

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    view.loadUrl(url);



                return true;
            }

            @Override
            public void onPageFinished(WebView view, final String url) {

                mySwipeRefreshLayout.setRefreshing(false);
            }
        });

            webView.loadUrl(url);

    }

Here is my java code I set the cookie also to web view and I set also layer type. I search that everyone says to set layer type then this problem solved but it does not solved.

xaif
  • 553
  • 6
  • 27
Asad Yasin
  • 93
  • 10

3 Answers3

1

try this

final WebSettings settings = mWebView.getSettings();
settings.setDomStorageEnabled(true);
settings.setJavaScriptEnabled(true);
mWebView.setVerticalScrollBarEnabled(false);
Momen Zaqout
  • 1,508
  • 1
  • 16
  • 17
  • try to remove all of this CookieManager.getInstance().setCookie(url, cookie); webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); webView.getSettings().setLoadWithOverviewMode(true); webView.getSettings().setUseWideViewPort(true); – Momen Zaqout Sep 08 '18 at 10:58
  • removing .setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); is okey for everything – Ucdemir Jun 27 '21 at 08:22
0

Just remove

webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);

all others are OK

Ucdemir
  • 2,852
  • 2
  • 26
  • 44
0

try this in AndroidManifest.xml

set android:hardwareAccelerated="true" in the application and activity tag.

Nur Alam
  • 192
  • 2
  • 8