覆盖方法的问题
我有一个RelativeLayout 的子类,我试图重写一些方法(所有addView(...) 方法),但我遇到了一个奇怪的问题。从“源”菜单生成覆盖时,我有以下内容
@Override
public void addView(View child)
{
// TODO Auto-generated method stub
super.addView(child);
}
@Override
public void addView(View child, int index)
{
// TODO Auto-generated method stub
super.addView(child, index);
}
@Override
public void addView(View child, int width, int height)
{
// TODO Auto-generated method stub
super.addView(child, width, height);
}
@Override
public void addView(View child, LayoutParams params)
{
// TODO Auto-generated method stub
super.addView(child, params);
}
@Override
public void addView(View child, int index, LayoutParams params)
{
// TODO Auto-generated method stub
super.addView(child, index, params);
}
但最后两个抛出该类型的编译错误
RelativeLayoutWithDataState 类型的方法 addView(View, int, RelativeLayout.LayoutParams) 必须重写或实现超类型方法
查看文档这些都是 API 级别 1
任何人都可以澄清一下这一点,我真的很傻吗?
谢谢!
I have a subclass of RelativeLayout and I am trying to override some methods (all the addView(...) methods) and I am having a strange problem. When generating the overrides from the Source menu I have the below
@Override
public void addView(View child)
{
// TODO Auto-generated method stub
super.addView(child);
}
@Override
public void addView(View child, int index)
{
// TODO Auto-generated method stub
super.addView(child, index);
}
@Override
public void addView(View child, int width, int height)
{
// TODO Auto-generated method stub
super.addView(child, width, height);
}
@Override
public void addView(View child, LayoutParams params)
{
// TODO Auto-generated method stub
super.addView(child, params);
}
@Override
public void addView(View child, int index, LayoutParams params)
{
// TODO Auto-generated method stub
super.addView(child, index, params);
}
But the last two throw compile errors of the type
The method addView(View, int, RelativeLayout.LayoutParams) of type RelativeLayoutWithDataState must override or implement a supertype method
looking at the docs these are all API level 1
Can anyone shed some light on this, am I being really stupid?!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您导入了错误的 LayoutParams。它应该是
ViewGroup.LayoutParams
而不是RelativeLayout.LayoutParams
这应该可以解决您的问题。
You've imported the wrong LayoutParams. It should be
ViewGroup.LayoutParams
and notRelativeLayout.LayoutParams
That should fix your problem.