Add the admob in a navigation drawer layout

1

I want to put the advertisement in the activity footer, but it is at the top overlapping a list:

<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<ListView
    android:id="@+id/list_slidermenu"
    android:layout_width="280dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:listSelector="#4DA6FF"
    android:background="#FFF"/>

<LinearLayout
    android:id="@+id/listaPropaganda"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"/>

Java, in the oncreate of activity:

AdView ads = new AdView(this);
    ads.setAdUnitId(ANUNCIO_ID);
    ads.setAdSize(com.google.android.gms.ads.AdSize.BANNER);
    LinearLayout layout = (LinearLayout) findViewById(R.id.listaPropaganda);
    layout.addView(ads);

    AdRequest request = new AdRequest.Builder().addTestDevice("1100").build();
    ads.loadAd(request);

I want to put it in the footer and fill in all the space. How to do this?

<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->

<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<ListView
    android:id="@+id/list_slidermenu"
    android:layout_width="280dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:listSelector="#4DA6FF"
    android:background="#FFF"/>

<LinearLayout
    android:id="@+id/listaPropaganda"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"/>

    
asked by anonymous 03.09.2014 / 18:10

1 answer

2

Replace your layout with the one below. Note that I changed the FrameLayout external by a LinearLayout with android:orientation="vertical" . Also note that the android:layout_weight="1" property has been added to your list. The height of it has gone to 0dp for optimization reasons, since the weight will define that it should fill all the remaining space between the two views.

If you prefer, you can also take the listaPropaganda of the layout and add your banner directly to container .

<LinearLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" />

    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="280dp"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:listSelector="#4DA6FF"
        android:background="#FFF"/>

    <LinearLayout
        android:id="@+id/listaPropaganda"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"/>

</LinearLayout>
    
03.09.2014 / 19:59