覆盖方法的问题

发布于 2024-12-11 09:02:06 字数 1351 浏览 0 评论 0原文

我有一个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

http://developer.android.com/reference/android/view/ViewGroup.html#addView(android.view.View, int, android.view.ViewGroup.LayoutParams)

任何人都可以澄清一下这一点,我真的很傻吗?

谢谢!

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

http://developer.android.com/reference/android/view/ViewGroup.html#addView(android.view.View, int, android.view.ViewGroup.LayoutParams)

Can anyone shed some light on this, am I being really stupid?!

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

世界如花海般美丽 2024-12-18 09:02:06

您导入了错误的 LayoutParams。它应该是 ViewGroup.LayoutParams 而不是 RelativeLayout.LayoutParams

这应该可以解决您的问题。

You've imported the wrong LayoutParams. It should be ViewGroup.LayoutParams and not RelativeLayout.LayoutParams

That should fix your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文