1

我在我的主布局上设置了一个 webview,但我无法以编程方式调整它的大小。Webview 处于“主要”布局中。如果对他的内容容器“layoutA”做同样的事情,但不是解决方案,我只需要设置 webview 视图。谢谢你。

protected void onCreate(Bundle savedInstanceState){
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            final RelativeLayout LayoutA = (RelativeLayout)findViewById(R.id.aLayout);
            webviewA = (WebView) findViewById(R.id.webviewA);           

            Handler handler = new Handler();
            final Runnable r = new Runnable()
            {
                public void run() 
                {
                     LayoutParams params = (LayoutParams) webviewA.getLayoutParams();

                      params.height -= 150;

                }
            };

            handler.postDelayed(r, 1000);

日志猫,

07-06 11:23:21.204: E/AndroidRuntime(13795): FATAL EXCEPTION: main
07-06 11:23:21.204: E/AndroidRuntime(13795): java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams
07-06 11:23:21.204: E/AndroidRuntime(13795):    at com.xxxx.projecte1.webPush$1.run(webPush.java:109)
07-06 11:23:21.204: E/AndroidRuntime(13795):    at android.os.Handler.handleCallback(Handler.java:587)
07-06 11:23:21.204: E/AndroidRuntime(13795):    at android.os.Handler.dispatchMessage(Handler.java:92)
07-06 11:23:21.204: E/AndroidRuntime(13795):    at android.os.Looper.loop(Looper.java:138)
07-06 11:23:21.204: E/AndroidRuntime(13795):    at android.app.ActivityThread.main(ActivityThread.java:3701)
07-06 11:23:21.204: E/AndroidRuntime(13795):    at java.lang.reflect.Method.invokeNative(Native Method)
07-06 11:23:21.204: E/AndroidRuntime(13795):    at java.lang.reflect.Method.invoke(Method.java:507)
07-06 11:23:21.204: E/AndroidRuntime(13795):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
07-06 11:23:21.204: E/AndroidRuntime(13795):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
07-06 11:23:21.204: E/AndroidRuntime(13795):    at dalvik.system.NativeStart.main(Native Method)
4

3 回答 3

0

在您的 WebView 上调用 invalidate()。见http://developer.android.com/reference/android/view/View.html(绘图部分)

问候弗洛

于 2012-07-06T09:31:37.107 回答
0

您已经在活动类中导入了 RelativeLayout.LayoutParams。

试着用

public void run() 
{
     ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) webviewA.getLayoutParams();
     params.height -= 150;    
}
于 2012-07-06T09:36:06.903 回答
0

问题出在导入的包中,请检查您的情况下的包,如果它不存在而不是添加它而不是其他 pkg,如 import android.widget.RelativeLayout 等...

 import android.view.ViewGroup.LayoutParams;
于 2012-07-06T09:52:43.953 回答