当我更改网页浏览量

时间:2018-03-22 12:45:25

标签: java android webview

我构建了显示webview的应用程序。 当我改变WebView的大小时,我的应用程序崩溃了。

这里是我的代码:

final WebView videoWebView = (WebView) findViewById(R.id.videoWebView);
    videoWebView.getSettings().setJavaScriptEnabled(true);
    videoWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    videoWebView.getSettings().setPluginState(PluginState.ON);
    videoWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(30, 30);
    videoWebView.setLayoutParams(layoutParams);

(这个webview隐藏在应用程序的开头,当我向他显示应用程序崩溃时) 你能帮助我吗?

非常感谢你!

我的退出:

java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams
at android.widget.FrameLayout.onMeasure(FrameLayout.java:186)
at android.view.View.measure(View.java:19759)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:911)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6122)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6122)
at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:393)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6122)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6122)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6122)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:690)
at android.view.View.measure(View.java:19759)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2313)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1400)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1649)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1288)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6359)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:873)
at android.view.Choreographer.doCallbacks(Choreographer.java:685)
at android.view.Choreographer.doFrame(Choreographer.java:621)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:859)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6326)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)

2 个答案:

答案 0 :(得分:3)

试试这个

ViewGroup.LayoutParams newParams=videoWebView.getLayoutParams();
        newParams.height=30;
        newParams.width=30;
        videoWebView.setLayoutParams(newParams);

或者这个

FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(30, 30); 
videoWebView.setLayoutParams(layoutParams);

答案 1 :(得分:0)

LinearLayout.LayoutParams替换为代码中的FrameLayout.LayoutParams

 LinearLayout.LayoutParams layoutParams =  LinearLayout.LayoutParams(30, 30);

with:

FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(30, 30);