我在我的主布局上设置了一个 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)