1

I want to know that how to prevent webview scrolling up when finished loading data form any url. For example, I'm loading data from http://stackoverflow.com in my webview, and when data loading (still image doesn't finish loading), I scroll down to view text in webview. Suddenly, Webview is auto scroll up because data is finish loading. So, how to fix this.

P/S: I have a method that I disable scroll of webview, then I put scrollview outside webview so I can solve my problem. But I have a new problem that when data change, the height of webview or scrollview (I think the height of scrollview) not change when i scroll down to the end of screen. It make my app have a large space in the bottom. I can't fix it.

2
  • maybe you can use progressbar to prevent user to interact with the webview till the page load finish. Commented Nov 16, 2011 at 3:39
  • 1
    Thank you so much. But when using progress dialog make people feel my app is slow. In my opinion, the text of page finished loading while images still loading. If using progress dialog, People must to wait the image is loading finish, and it take a long time. I think people can read text first while waiting image done. so progress dialog can't solve my problem. Commented Nov 16, 2011 at 3:57

2 Answers 2

1

Maybe you could keep a track of your WebView scroll position using onScrollChanged()

And when the page finishes loading, you can scrollTo()

public void onPageFinished(WebView view, String url) {
    // scroll to the stored position. 
}

By the way, on a couple of devices that I've tested your use case, this is Non-Repro. It could be something wrong in your code.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank Reno, It's perfect method.
1

I used a progress bar as RelativeLayout, instead of ProgressBar, and then set its click listener to null in onPageStarted() method. Here is my working solution to your problem:

private class MyBrowser extends WebViewClient {
    final RelativeLayout progressBar = (RelativeLayout) findViewById(R.id.progressBarLayout);

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

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        progressBar.setOnClickListener(null);
        progressBar.setVisibility(View.VISIBLE);
    }

    public void onPageFinished(WebView view, String url) {
        progressBar.setVisibility(View.GONE);
    }
}

Here is the related XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <RelativeLayout
        android:id="@+id/progressBarLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone" >

        <ProgressBar
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true" />
    </RelativeLayout>
</RelativeLayout>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.