Android Adwhirl 3.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,当我尝试让 AdWhirl 示例代码正常工作时,我做了与您相同的事情。问题是您已经在 XML 文件中使用 AdWhirlLayout 创建了一个布局,并且您正在检索该现有实例:
然后您尝试将其添加回您所拥有的 LinearLayout 中:
您只需删除 AdWhirlLayout从 XML 文件中替换我提到的第一行代码,创建一个新实例:(
我可能缺少构造函数的参数,我正在手动编写此代码。)
这将创建一个新实例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:
And then you're attempting to add it back into the LinearLayout you've got:
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:
(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.