Android How to align AdView to center in a linear layout

Don’t use LinearLayout as the AdView’s parent. Instead, use RelativeLayout and layout_centerInParent="true" for the AdView:

<RelativeLayout
    android:id="@+id/ad_holder"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:gravity="bottom" >

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        ads:adSize="BANNER"
        ads:adUnitId="MY_AD_UNIT_ID"
        ads:loadAdOnCreate="true"
        ads:testDevices="TEST_EMULATOR" >
    </com.google.ads.AdView>

</RelativeLayout>

Or just use android:layout_width="fill_parent" if you still want to work with LinearLayout.

Leave a Comment