3

我在ViewPager 中使用水平滚动 webview 的解决方案

它看起来很有用,我在 xml 中引用了 ExtendedWebView,

<ExtendedWebView
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>

.class 中的实例 ExtendedWebView,

LayoutInflater mInflater =  (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout  = mInflater.inflate(R.layout.lay1, null);
ExtendedWebView webView = (ExtendedWebView)layout.findViewById(R.id.webview);

但我得到'错误膨胀类 ExtendedWebView',所以任何人都可以帮助我给我一些想法,感谢您的时间和经验!

这是整个堆栈跟踪,

12-27 22:14:44.263: E/AndroidRuntime(10824): FATAL EXCEPTION: main
12-27 22:14:44.263: E/AndroidRuntime(10824): android.view.InflateException: Binary XML file line #7: Error inflating class com.vv_package_name.ExtendedWebView
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at com.vv_package_name.vv_main$ExtendedPagerAdapter.instantiateItem(vv_main.java:135)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.support.v4.view.PagerAdapter.instantiateItem(PagerAdapter.java:110)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:801)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.support.v4.view.ViewPager.populate(ViewPager.java:930)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.support.v4.view.ViewPager.populate(ViewPager.java:881)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1366)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.view.View.measure(View.java:8226)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.view.View.measure(View.java:8226)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.view.View.measure(View.java:8226)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.view.View.measure(View.java:8226)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.view.View.measure(View.java:8226)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.os.Looper.loop(Looper.java:123)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.app.ActivityThread.main(ActivityThread.java:4627)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at java.lang.reflect.Method.invokeNative(Native Method)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at java.lang.reflect.Method.invoke(Method.java:521)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at dalvik.system.NativeStart.main(Native Method)
12-27 22:14:44.263: E/AndroidRuntime(10824): Caused by: java.lang.ClassNotFoundException: com.vv_package_name.ExtendedWebView in loader dalvik.system.PathClassLoader[/data/app/com.vv_package_name-2.apk]
12-27 22:14:44.263: E/AndroidRuntime(10824):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.view.LayoutInflater.createView(LayoutInflater.java:466)
12-27 22:14:44.263: E/AndroidRuntime(10824):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
12-27 22:14:44.263: E/AndroidRuntime(10824):    ... 33 more

如果使用 WebView 而不是 ExtendedWebView,我的代码工作正常 :)

4

3 回答 3

5

您需要提供对该类的完整引用,包括包。

例如,

<org.example.myapp.ExtendedWebView
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
 />
于 2012-12-27T13:15:01.950 回答
1

抱歉,我是菜鸟,这是我的问题,我将这些扩展 webview 代码放在主 Activity 类中的一个 .class 文件中...它应该与独立的 .class 文件一起保存...:)

public class ExtendedWebView extends WebView {
于 2012-12-28T09:58:28.997 回答
1

通过在我的 XML 中使用它为我解决了:

 <view
    class="com.example.MainActivity$MyWebView"
    android:id="@+id/web_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
于 2013-09-14T15:30:08.767 回答