【发布时间】:2013-08-11 19:42:59
【问题描述】:
过去,我已经按照这种模式(在主要活动中)使用 LinearLayout 小部件成功地将 AdMob 广告集成到我的 Android PhoneGap 应用中:
AdMob/PhoneGap 集成 - 有效 - 在 main.xml 中不需要额外的标记
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
adView = new AdView(this, AdSize.BANNER, AdMob_Ad_Unit);
LinearLayout layout = super.root;
layout.addView(adView);
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
}
但是,我想使用 MoPub SDK 遵循类似的模式,我尝试了以下模式,然而,这并没有显示应用程序的 PhoneGap“webview”,尽管它正确加载了广告:
MoPub/PhoneGap 集成 - 广告有效,PhoneGap 无效 - 需要添加到 main.xml
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.loadUrl(Config.getStartUrl());
setContentView(R.layout.main);
moPubView = (MoPubView) findViewById(R.id.adview);
moPubView.setAdUnitId(MOPUB_ID);
moPubView.loadAd();
}
在main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.mopub.mobileads.MoPubView
android:id="@+id/adview"
android:layout_width="fill_parent"
android:layout_height="50dp"
/>
这就是显示的内容 - 我怎样才能让 PhoneGap 与 MoPub 一起工作?
【问题讨论】:
标签: android android-layout cordova mopub