I have a webview in a scrollview, when th开发者_如何学Pythone 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);
}
});
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 !
Create a custom ScrollView with this method:
@Override
public void requestChildFocus(View child, View focused) {
if (child instanceof WebView) return;
}
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.
add this to your main layout
android:descendantFocusability="blocksDescendants"
精彩评论