2012-04-13 2 views
4

고글 Adview를 목록의 아래쪽과 가운데에 정렬하려고합니다. 이제 Adview를 목록의 맨 아래에 오도록 강제 할 수있었습니다. 목록에 있지만 중앙에 오지는 않습니다.안드로이드 선형 레이아웃에서 중심에 맞추기 위해 AdView를 정렬하는 방법

코드가에서 AdView의 부모로 LinearLayout를 사용하지 마십시오 스크린 샷을

<?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> 

답변

8

를 첨부 cudn't, 아래 죄송 붙여 넣습니다.

<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

빙고 !!! 이것이 제가 찾고 있던 것입니다. 고마워 Alek – Shakti

0

사용 android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"

3

을 또는 당신은 여전히 ​​LinearLayout 작업 할 경우 단지 android:layout_width="fill_parent"를 사용 : 대신, AdView가에 대한 RelativeLayoutlayout_centerInParent="true"를 사용합니다.