Reputation: 825
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);
}
});
Upvotes: 6
Views: 3394
Reputation: 91
add this to your main layout
android:descendantFocusability="blocksDescendants"
Upvotes: 1
Reputation: 6884
For focus related issues, I found this worked better, adding these to your WebView in XML:
android:focusable="false"
android:focusableInTouchMode="false"
Although for the actual question asked, just adding another view that gets the focus by default, instead of the WebView, should have resolved that issue. I think others like me might find this when trying to deal with other general issues with a WebView inside a ScrollView taking the focus. Adding the above to the XML does not stop hyperlinks in the WebView from working.
Upvotes: 2
Reputation: 34530
Create a custom ScrollView with this method:
@Override
public void requestChildFocus(View child, View focused) {
if (child instanceof WebView) return;
}
Upvotes: 5
Reputation: 1553
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 !
Upvotes: 10