2012-02-28 32 views
1

http://i.stack.imgur.com/lbs7l.pngAdMob聯播背景下方

我想要的背景之下設置的AdMob,但我一直在這樣的背景上得到的AdMob。 http://i.stack.imgur.com/YJXU2.png

所以發生了什麼事是我有一個按鈕alignedParentBottom =「true」 但廣告仍在覆蓋按鈕。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<Button 
    android:id="@+id/backButton" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/back" 
    android:textSize="40sp" 
    android:layout_alignParentBottom="true" 
    ></Button> 

<ScrollView 
    android:id="@+id/ScrollView1" 

    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:layout_alignParentTop="true" 
    android:layout_above="@id/backButton"   
    > 

<TextView 
    android:id="@+id/TextView1" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:textSize="20sp" 

    android:text="@string/helphelp"></TextView> 
</ScrollView> 


<com.google.ads.AdView android:id="@+id/adView2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        ads:adUnitId="MY_UNIT_ID" 
        ads:adSize="BANNER" 
        ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" 
        ads:loadAdOnCreate="true" 
        android:layout_below="@id/backButton"></com.google.ads.AdView> 
+0

你試過FrameLayout嗎? – 2012-02-28 05:53:50

+0

不,我如何以及在哪裏實施? – sayhaha 2012-02-28 06:20:35

回答

1

您可以創建第二個RelativeLayout - 內部的一個將包含所有主要佈局內容,外部包含您的佈局內容和AdView。只需將AdView設置在底部,並將您的RelativeLayout內容設置爲AdView以上,並在廣告返回時強制後退按鈕。

爲了您的方便,我在此提供了代碼。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:layout_above="@+id/adView2"> 
     <Button 
      android:id="@+id/backButton" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/back" 
      android:textSize="40sp" 
      android:layout_alignParentBottom="true"> 
     </Button> 
     <ScrollView 
      android:id="@+id/ScrollView1" 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:layout_alignParentTop="true" 
      android:layout_above="@id/backButton"> 
      <TextView 
       android:id="@+id/TextView1" 
       android:layout_height="wrap_content" 
       android:layout_width="fill_parent" 
       android:textSize="20sp" 
       android:text="@string/helphelp"> 
      </TextView> 
     </ScrollView> 
    </RelativeLayout> 
    <com.google.ads.AdView android:id="@id/adView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     ads:adUnitId="MY_UNIT_ID" 
     ads:adSize="BANNER" 
     ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" 
     ads:loadAdOnCreate="true"> 
    </com.google.ads.AdView> 
</RelativeLayout> 

備註:確保您的UI元素不太靠近廣告;這可能會鼓勵意外點擊,並且違反AdMob的ToS。

0

使用FrameLayout

子視圖在一個組中獲得,在頂部最近添加的孩子。

沒有什麼。如果您想確保Button在AdView上繪製,請將AdView放置在一個常見的FrameLayout父級中。例如,

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
    <com.google.ads.AdView android:id="@+id/adView2" ... /> 
    <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
     ... Buttons, etc. ... 
    </RelativeLayout> 
</FrameLayout> 

雖然您可能只想在Button和AdView中的RelativeLayout的FrameLayout子。或者,您可能需要上述示例中的AdView的RelativeLayout父級來定位廣告。