I know that there are similar questions, and I have already tried and implemented all these solutions. However, none of them worked with me. Even though WebView has finished loading data, ScrollView never stops scrolling to the bottom. I want to use pull to update and hide the action bar with onScrollListener. Everything is fine, but I can’t prevent it scrolViewfrom continuously scrolling to the bottom.
I read the following: How can I prevent the scrollbar from scrolling to browsing after loading the data?
I read it too: webview makes my scrollview go down
I tried to implement a custom scrollviewone that overrides the method requestChildFocus.
I have added android:descendantFocusability="blocksDescendants"to my xml file.
I added android:focusableInTouchMode="true"too, but still no good, no change. It still forces you to scroll forever.
Here is my custom scroll:
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 that you opened Google.com in this web survey. After loading the page, it incredibly scrolls down, you can’t even see any information at the bottom of the page. How can I fix this problem? Any help would be greatly appreciated! Thanks in advance!
By the way, the addition android:descendantFocusability="blocksDescendants" causes problems , since you cannot search immediately after opening Google.com, you cannot enter any data into the Google search bar!