How to prevent a scrollview from scrolling to a webview after data is loaded?
Solution 1:
I had the same problem, after hours of trying several ideas, what finally worked for me was simply adding the descendantFocusability
attribute to the ScrollView's containing LinearLayout, with the value blocksDescendants
. In your case:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants" >
Haven't had the problem reoccur since.
Solution 2:
You can simply add this to your LinearLayout: android:focusableInTouchMode="true". It works for me.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:orientation="vertical" >
Solution 3:
You should create new class extend ScrollView, then Override requestChildFocus:
public class MyScrollView extends ScrollView {
@Override
public void requestChildFocus(View child, View focused) {
if (focused instanceof WebView )
return;
super.requestChildFocus(child, focused);
}
}
Then in your xml layout, using:
<MyScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background" >
That works for me. The ScrollView will not auto scroll to the WebView anymore.