AdWhirl不渲染Android
我第一次在我们的应用程序中使用Adwhirl,但没有乐趣。。Adwhirl提供了此演示代码,但它在下面选中的行上提示错误“java.lang.ClassCastException:android.widget.LinearLayout”AdWhirl不渲染Android,android,adwhirl,Android,Adwhirl,我第一次在我们的应用程序中使用Adwhirl,但没有乐趣。。Adwhirl提供了此演示代码,但它在下面选中的行上提示错误“java.lang.ClassCastException:android.widget.LinearLayout” AdWhirlManager.setConfigExpireTimeout(1000 * 60 * 5); AdWhirlTargeting.setAge(23); AdWhirlTargeting.setGender(
AdWhirlManager.setConfigExpireTimeout(1000 * 60 * 5);
AdWhirlTargeting.setAge(23);
AdWhirlTargeting.setGender(AdWhirlTargeting.Gender.MALE);
AdWhirlTargeting.setKeywords("online games gaming");
AdWhirlTargeting.setPostalCode("94123");
AdWhirlTargeting.setTestMode(false);
***AdWhirlLayout adWhirlLayout = (AdWhirlLayout) findViewById(R.id.layout_ad);***
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.test_layout);
layout.setGravity(Gravity.CENTER_HORIZONTAL);
layout.addView(adWhirlLayout, layoutParams);
layout.addView(textView, layoutParams);
layout.invalidate();
这里是XML
谢谢将此行更改为
AdWhirlLayout adWhirlLayout = (AdWhirlLayout) findViewById(R.id.layout_ad);// change this
到
在布局XML中,adwhirl布局不应定义为
LinearLayout
,而应定义为AdWhirlLayout
不要忘记将XML命名空间添加到布局文件的根元素:
xmlns:app="http://schemas.android.com/apk/res/com.adwhirl"
但是,com.adwhill.adwhilllayout
元素本身可能存在于LinearLayout
中
以下是一个XML代码片段示例:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.adwhirl
... other LinearLayout attributes here">
<com.adwhirl.AdWhirlLayout
android:id="@+id/adwhirl_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
...other elements here
…这里还有其他元素
我不知道什么是AdWhilLayout,但例外情况是,您正在将线性布局类型转换为AdWhilLayout
xmlns:app="http://schemas.android.com/apk/res/com.adwhirl"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.adwhirl
... other LinearLayout attributes here">
<com.adwhirl.AdWhirlLayout
android:id="@+id/adwhirl_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
...other elements here