WebView水平滚动失败 [英] WebView horizontal scrolling fails
问题描述
片段中的WebView出现了一个奇怪的问题.水平滚动无法正常工作.它只滚动一点.没问题,可以垂直滚动内容,捏以缩放,是的,在捏住的同时用两根手指移动页面也可以在所有方向上使用.
I've got a strange issue with a WebView inside a fragment. The horizontal scrolling doesn't work properly. It scrolls only a bit. It's no problem, to scroll the content vertically, pinch to zoom, and yes, moving the page with two fingers while pinching also works in all directions.
这是Fragment的onCreateView()方法,带有WebView.我不能使用WebViewFragment. 该片段位于Viewpager中!提供的数据是有效的html5文档.但是我也没有成功尝试真实网页".
This is the onCreateView()-Method of the Fragment, that carries the WebView. I can't use WebViewFragment. This Fragment is inside a Viewpager! The provided data is a valid html5 document. But I've not successfully tried a "real webpage" as well.
this.mView = inflater.inflate(R.layout.search_results, container, false);
mWebView = (WebView)this.mView.findViewById(R.id.search_results);
mWebView.setWebViewClient(new SearchResultsWebViewClient());
mWebView.setInitialScale(120);
mWebView.setScrollContainer(true);
mWebView.bringToFront();
mWebView.setScrollbarFadingEnabled(true);
mWebView.setVerticalScrollBarEnabled(true);
mWebView.setHorizontalScrollBarEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setJavaScriptEnabled(false);
mWebView.loadData(this.data, "text/html", "utf-8");
return this.mView;
这是search_results.xml
This is the search_results.xml
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id ="@+id/search_results"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</WebView>
以及加载片段的布局文件
And the layout-file in which the fragment is loaded
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false"
android:weightSum="1.0">
<LinearLayout android:layout_weight="0.5"
android:layout_width="0dip"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:drawSelectorOnTop="false"/>
</LinearLayout>
<LinearLayout android:layout_weight="0.5"
android:layout_width="0dip"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout android:id="@+id/resultsWebWiewFragmentFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</LinearLayout>
由于我使用的是ABS,因此无法直接将片段加载到xml文件中.这将引发ClassCastException.
Because I'm using ABS, it isn't possible to load the fragment directly in the xml file. This'll throw a ClassCastException.
推荐答案
我刚刚对此进行了搜索,并在查看此答案,看看是否有帮助.
I just searched this and ran into the same question on SO, check out this answer and see if that helps.
他添加了以下内容:
mWebView.getSettings().setUseWideViewPort(true);
是的,似乎ViewPager
消耗了您的水平滚动,请查看这两种解决方案.希望他们能帮上忙.
Yeah It seems like the ViewPager
consumes your horizontal scroll, check out these two solutions. Hopefully they help.
- Solution 1
- Solution 2
这篇关于WebView水平滚动失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!