用于webview的android setLayoutParams生成错误

时间:2011-06-11 10:17:36

标签: android webview layoutparams

是否可以设置

mWebView = (WebView) findViewById(R.id.webviewHelp);
        mWebView.setLayoutParams(new ViewGroup.LayoutParams(100, 200));

这里

 mWebView.setLayoutParams(new Gallery.LayoutParams(70,85));

也经过测试但没有工作:(

在我的活动中? 我的xml文件如下

(这里我要在我的应用程序中通过XML创建webview)

 <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"   android:id="@+id/rl"
        android:layout_height="360dip">
    <!--    <WebView android:id="@+id/webviewHelp" android:layout_width="fill_parent"-->
    <!--        android:layout_height="fill_parent" />-->
    <WebView android:id="@+id/webviewHelp" android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
        <Button android:id="@+id/My_btn"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true" android:gravity="center" android:textSize="8px" android:text="Download this mp3 file"
    android:textColor="@color/white" 
            android:layout_width="fill_parent" android:layout_height="33dip"
            android:visibility="invisible" />
        <Button android:id="@+id/My_btn1"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true" android:text="this is button !"
            android:layout_width="0dip" android:layout_height="0dip"
            android:visibility="invisible" />
    </RelativeLayout>

我正在收到此错误并且应用程序强行关闭

06-11 15:42:51.816: DEBUG/AndroidRuntime(323): Shutting down VM
06-11 15:42:51.816: WARN/dalvikvm(323): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
06-11 15:42:51.816: ERROR/AndroidRuntime(323): Uncaught handler: thread main exiting due to uncaught exception
06-11 15:42:51.835: ERROR/AndroidRuntime(323): java.lang.ClassCastException: android.view.ViewGroup$LayoutParams
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.RelativeLayout$DependencyGraph.findRoots(RelativeLayout.java:1291)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.RelativeLayout$DependencyGraph.getSortedViews(RelativeLayout.java:1238)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.RelativeLayout.sortChildren(RelativeLayout.java:279)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:299)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.View.measure(View.java:7703)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.View.measure(View.java:7703)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.View.measure(View.java:7703)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.View.measure(View.java:7703)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:569)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:361)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.View.measure(View.java:7703)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.View.measure(View.java:7703)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.View.measure(View.java:7703)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:464)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:278)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.View.measure(View.java:7703)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.View.measure(View.java:7703)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.ViewRoot.performTraversals(ViewRoot.java:747)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1613)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.os.Looper.loop(Looper.java:123)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at android.app.ActivityThread.main(ActivityThread.java:4203)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at java.lang.reflect.Method.invokeNative(Native Method)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at java.lang.reflect.Method.invoke(Method.java:521)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
06-11 15:42:51.835: ERROR/AndroidRuntime(323):     at dalvik.system.NativeStart.main(Native Method)
06-11 15:42:51.845: INFO/Process(52): Sending signal. PID: 323 SIG: 3
06-11 15:42:51.845: INFO/dalvikvm(323): threadid=7: reacting to signal 3
06-11 15:42:51.857: ERROR/dalvikvm(323): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
06-11 15:42:52.566: DEBUG/dalvikvm(99): GC freed 4505 objects / 251696 bytes in 293ms

我在做什么?提前谢谢:Pragna

1 个答案:

答案 0 :(得分:10)

而不是:

   mWebView = (WebView) findViewById(R.id.webviewHelp);    
   mWebView.setLayoutParams(new ViewGroup.LayoutParams(100, 200));

使用:

   mWebView = (WebView) findViewById(R.id.webviewHelp);        
   LayoutParamters lp = mWebView.getLayoutParams();    
   lp.width=100;   
   lp.height=200;   
   mWebView.setLayoutParams(lp);