Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webview is forcing my scrollview to the bottom

I have a webview in a scrollview, when the Activity loads, it forces my scrollview to the bottom (where the webview is) once the webview finishes "loadData". How do I keep this from happening? I've tried this, but it jumps the screen up and down, which I don't want:

ScrollView scroll = (ScrollView)findViewById(R.id.detailsScroll);  
scroll.post(new Runnable()   
{  
    @Override  
    public void run()   
    {  
       ScrollView scroll = (ScrollView)findViewById(R.id.detailsScroll);  
       scroll.fullScroll(ScrollView.FOCUS_UP);  
    }  
});  
like image 653
steve Avatar asked Dec 30 '10 22:12

steve


1 Answers

The answer of fhucho is OK for stoping the webview from scrolling to bottom. But you will lose all accessibility with trackball, etc. So I found an improvement :

public class MyScrollView extends ScrollView {

    @Override 
    public void requestChildFocus(View child, View focused) { 
        if (focused instanceof WebView ) 
           return;
    super.requestChildFocus(child, focused);
    }
}

Hope it helps !

like image 174
Sylphe Avatar answered Oct 21 '22 04:10

Sylphe