我知道有类似的问题,我已经尝试并实施所有这些解决方案建议。但是,他们都没有和我一起工作。尽管WebView完成加载数据,但ScrollView从不停止滚动到底部。我想用拉来刷新并隐藏操作栏onScrollListener
。一切都很好,但我无法阻止从不停滚动到底部的scrolView
。如何停止滚动浏览到WebView当前加载页面的底部
我这样说的:How to prevent a scrollview from scrolling to a webview after data is loaded?
我读这还有:webview is forcing my scrollview to the bottom
我试图实现一个自定义scrollview
它覆盖requestChildFocus
方法。
我将android:descendantFocusability="blocksDescendants"
添加到我的xml文件中。
我也加了android:focusableInTouchMode="true"
,但还是不行,没有变化。它仍然强制永久滚动。
这里是我的自定义滚动型:
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);
}
}
这里是我的xml文件:
<?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>
例如想象你在此的WebView打开Google.com。页面加载完成后,它会不可思议地向下滚动到底部,甚至不能在页面底部看到任何信息。我该如何解决这个问题?任何帮助将非常感谢!提前致谢!
通过添加android:descendantFocusability="blocksDescendants"
导致问题像曾经Google.com打开,你不能进入任何输入到谷歌的搜索栏,你不能搜索的方式!