Question

I am trying to make the ads look as part of the app by placing them inside a view with a custom background. This is the result that I want to achieve - actually it's a preview from the layout editor:

enter image description here

When I run the app, however, the background and the "Sponsorized" text are not shown. How can I make it work?

This is my current layout for the view:

<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>
Was it helpful?

Solution

Create an another inner LinearLayout as parent to AdView . Use this

 <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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top