将adMob横幅放在视图中

时间:2014-05-02 14:41:21

标签: android admob

我试图通过将广告放置在具有自定义背景的视图中来使广告看起来像应用的一部分。这是我想要实现的结果 - 实际上它是布局编辑器的预览:

enter image description here

然而,当我运行应用程序时,背景和"赞助商"文字未显示。我怎样才能使它发挥作用?

这是我目前的视图布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <com.google.android.gms.ads.AdView android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adUnitId="@string/admob_id"
        ads:adSize="MEDIUM_RECTANGLE"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sponsorized"
        />

</LinearLayout>

1 个答案:

答案 0 :(得分:1)

创建另一个内部LinearLayout作为AdView的父级。使用此

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:ads="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"
          android:layout_margin="10dp"
          android:background="@color/white">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="20dp">
    <com.google.android.gms.ads.AdView android:id="@+id/adView"
                                       android:layout_width="match_parent"
                                       android:layout_height="wrap_content"
                                       ads:adUnitId="@string/admob_id"
                                       ads:adSize="MEDIUM_RECTANGLE"/>
</LinearLayout>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Sponsorized"/>

</LinearLayout>
相关问题