Android Adwhirl 3.0布局问题



你好,我想让新的android 3.0 adwhirl工作,我很挣扎。

在我的xml中,我有:

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();
    ...

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

指定的子节点已经有父节点。你必须首先调用removeView()在子的父。

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

谢谢朋友。

当我试图获得AdWhirl示例代码工作时,我实际上做了与您相同的事情。问题是你已经创建了一个布局w/AdWhirlLayout在XML文件中,你正在检索现有的实例:

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

然后你试图将它添加回LinearLayout你有:

layout.addView(adWhirlLayout, layoutParams);

您可以从XML文件中删除AdWhirlLayout,并将我提到的第一行代码替换为创建新实例:

AdWhirlLayout adWhirlLayout = new AdWhirlLayout();  

(我可能遗漏了构造函数的参数,我在SO上手写出来)

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

最新更新