片段中有WebView
。有时当我向下滚动时,视图会上升,反之亦然。
我加载WebView的代码是:
webView = (WebView)v.findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setDomStorageEnabled(true);
webView.setWebChromeClient(new WebChromeClient(){
public void onProgressChanged(WebView view, int progress) {
getActivity().setTitle("Loading...");
getActivity().setProgress(progress * 100);
if(progress == 100)
getActivity().setTitle("2Mummy");
}
});
webView.loadUrl("http://my_url_here");
webView.setOnKeyListener(new View.OnKeyListener(){
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK
&& event.getAction() == MotionEvent.ACTION_UP
&& webView.canGoBack()) {
handler.sendEmptyMessage(1);
return true;
}
return false;
}
});
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
if ((webView.canGoBack()) || (url!=url)){
}
else{
}
return false;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon){
}
@Override
public void onPageFinished(WebView view, String url){
webView.setVisibility(View.VISIBLE);
}
});
webView.scrollTo(0,webView.getContentHeight());
我的片段xml是
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/categoriesfrag"
tools:context="com.quadcircles.tomummy.Fragment.Categories">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView"/>
当我从手机加载网站时,它会完美滚动,当我在WebView
中加载同一网站时会出现问题。
感谢您的建议