【发布时间】:2012-01-23 09:22:50
【问题描述】:
我创建了一个名为 MyDraw 的自定义视图,这是我的 MyDraw 代码,
public class MyDraw extends View {
public MyDraw(Context context) {
super(context);
}
public MyDraw(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MyDraw(Context context, AttributeSet attrs) {
super(context, attrs);
}
........................................
}
我已经使用包名在 XML 文件中添加了视图。它工作正常。现在我想在运行时为 MyDraw 设置高度和宽度,因为我使用了以下代码,
mMyDraw.setLayoutParams(new LayoutParams(220, 300));
但我得到了类似的异常,
java.lang.ClassCastException: android.view.ViewGroup$LayoutParams
如何解决这个异常? 请帮帮我..
【问题讨论】:
标签: android android-layout classcastexception