1
我有一个奇怪的问题,一个片段内的WebView。水平滚动无法正常工作。它只滚动一点。垂直滚动内容,捏缩放,是的,用两根手指移动页面,同时捏也适用于所有方向。WebView水平滚动失败
这是onCreateView() - 片段的方法,它携带WebView。我无法使用WebViewFragment。 这个片段在Viewpager中!提供的数据是一个有效的html5文档。但我还没有成功尝试过一个“真正的网页”。
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
<?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>
以及其中由于我使用的是ABS的片段被加载
<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>
布局文件,这是不可能的直接在XML文件中加载片段。这会抛出一个ClassCastException。
嘿奥绍克。不,这使情况更糟。我认为这与ViewPager失败。寻呼机或WebView正在收集水平滚动。也许我错了。我发布了横向视图。在纵向上,此WebView作为单个片段添加到ViewPager。你有没有试过在WiewPager中水平滚动WebView?这不会工作;)但没有“分页”的viewpager没有意义。 – wog 2012-07-26 12:48:31
对不起,我第一次研究,我没有包括你使用'viewPager'的事实。请参阅上面编辑我的答案。 – jnthnjns 2012-07-26 13:18:15
嘿,没问题。其实这些答案正在解决滚动问题。也许我选择了错误的标题。在ViewPager中搜索“WebView”使得这个问题变得不必要;)正如我所说的,从作为界面设计者的角度来看,根据当前比例或其他状态在ViewPager中滚动WebView可能没有多大意义。我想,我要么将标签添加到肖像视图,要么玩这个美妙的ActionBarSherlock ... – wog 2012-07-26 13:50:46