Android Adwhirl 3.0 布局问题

发布于 2024-11-04 09:22:43 字数 1326 浏览 6 评论 0原文

嗨,我正在尝试让新的 android 3.0 adwhirl 正常工作,但我很挣扎。

在我的 xml 中我有:

在我的班级中

...

setContentView(R.layout.main);

    //Add Whirl
    AdWhirlManager.setConfigExpireTimeout(1000 * 60 * 5);

    AdWhirlTargeting.setTestMode(false);

    AdWhirlLayout adWhirlLayout = (AdWhirlLayout)findViewById(R.id.adwhirl_layout);

    TextView textView = new TextView(this);
    RelativeLayout.LayoutParams layoutParams = new
    RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    int diWidth = 320;
    int diHeight = 52;
    int density = (int) getResources().getDisplayMetrics().density;

    adWhirlLayout.setAdWhirlInterface(this);
    adWhirlLayout.setMaxWidth((int)(diWidth * density));
    adWhirlLayout.setMaxHeight((int)(diHeight * density));

    layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    textView.setText("Below AdWhirlLayout");

    LinearLayout layout = (LinearLayout)findViewById(R.id.layout_main);

    layout.setGravity(Gravity.CENTER_HORIZONTAL);
    layout.addView(adWhirlLayout, layoutParams);
    layout.addView(textView, layoutParams);
    layout.invalidate();

    ...

但是,当我运行它时,我得到

指定的孩子已经有一个父母。您必须首先对子级的父级调用removeView()。

我知道这可能是一个简单的布局问题,但我看不到解决方案,任何帮助将不胜感激。

谢谢朋友们。

Hi I'm trying to get the new android 3.0 adwhirl working and I'm struggling.

In my xml I have:

In my Class

...

setContentView(R.layout.main);

    //Add Whirl
    AdWhirlManager.setConfigExpireTimeout(1000 * 60 * 5);

    AdWhirlTargeting.setTestMode(false);

    AdWhirlLayout adWhirlLayout = (AdWhirlLayout)findViewById(R.id.adwhirl_layout);

    TextView textView = new TextView(this);
    RelativeLayout.LayoutParams layoutParams = new
    RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    int diWidth = 320;
    int diHeight = 52;
    int density = (int) getResources().getDisplayMetrics().density;

    adWhirlLayout.setAdWhirlInterface(this);
    adWhirlLayout.setMaxWidth((int)(diWidth * density));
    adWhirlLayout.setMaxHeight((int)(diHeight * density));

    layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    textView.setText("Below AdWhirlLayout");

    LinearLayout layout = (LinearLayout)findViewById(R.id.layout_main);

    layout.setGravity(Gravity.CENTER_HORIZONTAL);
    layout.addView(adWhirlLayout, layoutParams);
    layout.addView(textView, layoutParams);
    layout.invalidate();

    ...

However when I run it I get

The specified child already has a parent. You must call removeView() on the child's parent first.

I know it's probably a simple layout issue, but I'can't see a solution, any help would be appreciated.

Thanks friends.

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

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

发布评论

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

评论(1

念三年u 2024-11-11 09:22:43

实际上,当我尝试让 AdWhirl 示例代码正常工作时,我做了与您相同的事情。问题是您已经在 XML 文件中使用 AdWhirlLayout 创建了一个布局,并且您正在检索该现有实例:

AdWhirlLayout adWhirlLayout = (AdWhirlLayout)findViewById(R.id.adwhirl_layout);

然后您尝试将其添加回您所拥有的 LinearLayout 中:

layout.addView(adWhirlLayout, layoutParams);

您只需删除 AdWhirlLayout从 XML 文件中替换我提到的第一行代码,创建一个新实例:(

AdWhirlLayout adWhirlLayout = new AdWhirlLayout();  

我可能缺少构造函数的参数,我正在手动编写此代码。)

这将创建一个新实例AdWhirlLayout 并将其添加到您的layout_main LinearLayout 中。

I actually did the same thing as you when I was trying to get the AdWhirl sample code working. The problem is you've created a layout w/ the AdWhirlLayout in the XML file and you're retrieving that existing instance:

AdWhirlLayout adWhirlLayout = (AdWhirlLayout)findViewById(R.id.adwhirl_layout);

And then you're attempting to add it back into the LinearLayout you've got:

layout.addView(adWhirlLayout, layoutParams);

You can just drop the AdWhirlLayout from the XML file and replace the first line of code I mentioned w/ one creating a new instance:

AdWhirlLayout adWhirlLayout = new AdWhirlLayout();  

(I might be missing params for the constructor, I'm writing this out by hand on SO.)

That'll create a new instance of the AdWhirlLayout and add it to your layout_main LinearLayout.

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