1

I'm trying to place an adview at the bottom of every screen by injecting a fragment into a container. I can get the adview to be at the top, below the action bar, by using a LinearLayout. I've tried various combinations of RelativeLayout, but none seem to make the resizing-on-orientation adview stick.

Here's the layout that works for up top:

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

    <com.google.android.gms.ads.AdView android:id="@+id/adView"
                                       android:layout_width="wrap_content"
                                       android:layout_height="wrap_content"
                                       ads:adSize="SMART_BANNER"/>
</LinearLayout>

And I add fragments to fragmentContainer. How can I make the adview statically positioned at the bottom of the screen? I've tried various layout nesting strategies and none have worked so far.

The banner should not overlay or cut off any part of the fragment.

Stefan Kendall
  • 66,414
  • 68
  • 253
  • 406

1 Answers1

4

What about RelativeLayout with alignParentBottom attribute? Also, it's not a good practice to add a fragment inside another viewgroup than FrameLayout. This will not stuck or break your activity but it might provide some bugs. Something like this should do the trick:

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

    <com.google.android.gms.ads.AdView 
        android:layout_alignParentBottom="true"
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER" />

    <FrameLayout
        android:id="@+id/fragmentContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/adView" />

</RelativeLayout> 

Hope this helps.

Blo
  • 11,903
  • 5
  • 45
  • 99
  • This causes the banner to overlay the view and cut off the bottom of whatever is in the fragment. – Stefan Kendall Apr 18 '14 at 12:20
  • @StefanKendall I updated my answer according to your needs. Normally, the fragment will stays above the adView with the `layout_above` attribute. Let me know if this is what you expected. – Blo Apr 18 '14 at 12:34