我第一次在我们的应用程序中使用 Adwhirl,但没有任何乐趣.. Adwhirl 提供了这个演示代码,但它在下面的选定行上提示错误“java.lang.ClassCastException:android.widget.LinearLayout”
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
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:gravity="bottom" android:id="@+id/layout_ad" />
谢谢