因此,使用新的google-admob SDK for android,在布局中放置横幅广告的正确方式如下所示:
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_gravity="bottom"
android:layout_height="wrap_content"
ads:adUnitId="some id"
ads:adSize="BANNER"/>我的问题是,我在各种活动中有多个横幅广告,当我出于某种原因想要更改adUnitId时,我不想在我的所有xml布局文件中追逐这段代码。我想有一个地方,我定义我的adUnitId,在应用程序中的所有横幅广告使用。在之前的纯admob SDK中,通过在清单文件中设置元数据,这是可能的。我不想在Java代码中布局AdView,如果可能的话,希望它在新的开发工具包中。我尝试过这样的东西:
ads:adUnitId="@string/admob_id"但正如我所见,它只是将其视为一个字符串,而不是一直到strings.xml中定义的实际字符串。有什么想法吗?
发布于 2011-05-06 05:12:20
有了最新的admob更新,我不得不在我的Java类中完成大多数AdMob活动。这就是我是如何工作的(使用一个集中的ID):
ad = new AdView(this, AdSize.BANNER, UtilClass.AD_PUBLISHER_ID); //Ad is the global AdView
LinearLayout layout = (LinearLayout) findViewById(R.id.main_admob_layout);编辑:我将LinearLayout定义保存在xml文件中,这样定位就可以在整个xml中完成:
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="bottom" android:weightSum="0"
android:layout_alignParentBottom="true" android:id="@+id/main_admob_layout">https://stackoverflow.com/questions/5903980
复制相似问题