I know there are similar questions and I already tried and implemented all those solution suggestions. However, none of them worked with me.Even Though WebView Finished Loading Data, ScrollView Never Stops Scrolling to the Bottom. I want to use pull to refresh and hide the action bar with onScrollListener
. Everything is good but I can't prevent scrolView
from non-stop scrolling to the bottom.
I read this: How to prevent a scrollview from scrolling to a webview after data is loaded?
I read this as well: webview is forcing my scrollview to the bottom
I tried to implement a custom scrollview
which overrides requestChildFocus
method.
I added android:descendantFocusability="blocksDescendants"
to my xml file.
I added android:focusableInTouchMode="true"
too but still no good, no change. It still forces to scroll forever.
Here is my Custom scrollview:
package com.example.john.cosmicbrowser;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.webkit.WebView;
import android.widget.ScrollView;
public class MyScrollView extends ScrollView
{
public MyScrollView(Context context)
{
super(context);
}
public MyScrollView(Context context, AttributeSet attributeSet)
{
super(context, attributeSet);
}
public MyScrollView(Context context, AttributeSet attributeSet, int defStyle)
{
super(context, attributeSet, defStyle);
}
@Override
public void requestChildFocus(View child, View focused)
{
if (focused instanceof WebView)
return;
super.requestChildFocus(child, focused);
}
}
Here is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".WebActivity"
tools:showIn="@layout/activity_webview"
>
<com.example.john.cosmicbrowser.MyScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:descendantFocusability="blocksDescendants"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
>
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:padding="0dp"/>
<ProgressBar
android:id="@+id/cosmicProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:indeterminate="false"/>
</RelativeLayout>
</com.example.john.cosmicbrowser.MyScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
For example imagine you opened Google.com on this webview. After page loaded it incredibly scrolls down to the bottom you can't even see any information at the bottom of the page. How can I fix this problem? Any help would be extremely appreciated! Thanks in advance!
By the way adding android:descendantFocusability="blocksDescendants"
causing problems like you can't search once Google.com opened you can't enter any input to the Google's search bar!