0

我已經成功在廣告佈局的底部放置了廣告,效果很好。Admob廣告干擾了內部佈局中的元素

我的佈局有四個按鈕,但添加會干擾所有這些按鈕,提高它們。我希望按鈕在佈局中居中並且在底部添加,而不需要修改按鈕的位置。

這裏是我的XML代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
android:gravity="center" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingLeft="0dp" 
android:paddingRight="0dp" 
android:paddingBottom="0dp" > 

<com.google.android.gms.ads.AdView android:id="@+id/adView" 
        android:layout_alignParentBottom="true" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        ads:adUnitId="ca-app-pub-5943098653743528/9263521291" 
        ads:adSize="BANNER"/> 

<Button 
    android:id="@+id/pers" 
    android:layout_width="250dp" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="10dp" 
    android:textSize="15sp" 
    android:textColor="#ffffff" 
    android:text="@string/pers" 
    android:background="@drawable/custombutton1" /> 

<Button 
    android:id="@+id/university" 
    android:layout_width="250dp" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/pers" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="10dp" 
    android:textSize="15sp" 
    android:textColor="#ffffff" 
    android:text="@string/university" 
    android:background="@drawable/custombutton2" /> 

<Button 
    android:id="@+id/help" 
    android:layout_width="250dp" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/university" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="10dp" 
    android:textSize="15sp" 
    android:textColor="#ffffff" 
    android:text="@string/help" 
    android:background="@drawable/custombutton3" /> 

<Button 
    android:id="@+id/information" 
    android:layout_width="250dp" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/help" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="10dp" 
    android:textSize="15sp" 
    android:textColor="#ffffff" 
    android:text="@string/information" 
    android:background="@drawable/custombutton5" /> 

希望有一個解決方案!謝謝!

回答

0

使用FrameLayout在您的主UI組件上對廣告進行分層。 FrameLayout按引入的順序堆疊元素。

在這種情況下,RelativeLayout將成爲第一層,廣告將疊加在其上。我使用android:layout_gravity="bottom"將廣告定位在育兒FrameLayout的底部。

此外,您的按鈕正對齊到他們育兒RelativeLayout的頂部,這就是將它們帶到視圖的頂部。刪除那個爲RelativeLayoutandroid:gravity="center"工作。

希望這有助於!

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

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center"> 
<Button 
    android:id="@+id/pers" 
    android:layout_width="250dp" 
    android:layout_height="wrap_content" 
    android:textSize="15sp" 
    android:textColor="#ffffff" 
    android:text="@string/pers" 
    android:background="@drawable/custombutton1" /> 

<Button 
    android:id="@+id/university" 
    android:layout_width="250dp" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/pers" 
    android:textSize="15sp" 
    android:textColor="#ffffff" 
    android:text="@string/university" 
    android:background="@drawable/custombutton2" /> 

<Button 
    android:id="@+id/help" 
    android:layout_width="250dp" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/university" 
    android:textSize="15sp" 
    android:textColor="#ffffff" 
    android:text="@string/help" 
    android:background="@drawable/custombutton3" /> 

<Button 
    android:id="@+id/information" 
    android:layout_width="250dp" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/help" 
    android:textSize="15sp" 
    android:textColor="#ffffff" 
    android:text="@string/information" 
    android:background="@drawable/custombutton5" /> 
</RelativeLayout> 

<com.google.android.gms.ads.AdView android:id="@+id/adView" 
        android:layout_gravity="bottom 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        ads:adUnitId="ca-app-pub-5943098653743528/9263521291" 
        ads:adSize="BANNER"/> 
</FrameLayout>