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>