2012-04-13 16 views
4

Ich versuche, gogole Adview auf den Boden und das Zentrum einer Liste auszurichten, bis jetzt war ich in der Lage zu zwingen, die Adview am Ende der Liste kommen, ohne mit der Liste, aber es kommt nicht in der Mitte.Android Wie AdView zu zentrieren in einem linearen Layout

-Code ist unten eingefügt, Sorry Der Screenshot cudn't befestigen

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:id="@+id/topLayout" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" > 

    <LinearLayout 
     android:id="@+id/linearlayoutlistview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@+id/ad_holder" 
     android:orientation="vertical" > 

     <ListView 
      android:id="@android:id/list" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="2dip" 
      android:drawablePadding="4dip" 
      android:paddingTop="2dip" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textStyle="bold" 
      android:typeface="serif" > 
     </ListView> 
    </LinearLayout> 

    <!-- Ad Placeholder --> 

    <LinearLayout 
     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" 
      ads:adSize="BANNER" 
      ads:adUnitId="MY_AD_UNIT_ID" 
      ads:loadAdOnCreate="true" 
      ads:testDevices="TEST_EMULATOR" > 
     </com.google.ads.AdView> 

    </LinearLayout> 

</RelativeLayout> 

Antwort

8

Sie Eltern nicht LinearLayout als die des AdView verwenden. Verwenden Sie stattdessen RelativeLayout und layout_centerInParent="true" für die 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> 
+0

Bingo !!! Das ist, was ich gesucht habe. Vielen Dank Alek – Shakti

0

Verwenden android:layout_alignParentBottom="true" und android:layout_centerHorizontal="true"

3

Oder nur android:layout_width="fill_parent" verwenden, wenn Sie noch mit LinearLayout arbeiten wollen.

Verwandte Themen