我已成功将广告放置在版面的底部,效果很好。
我的布局有四个按钮,但添加会干扰所有这些按钮,提升它们。我希望按钮在布局中居中,在底部添加,而不修改按钮的位置。
以下是我的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 :(得分:0)
使用FrameLayout
将广告分层到主UI组件上。 FrameLayout
按引入顺序堆叠元素。
在这种情况下,RelativeLayout
将是第一层,广告将堆叠在其上。我使用android:layout_gravity="bottom"
将广告定位在育儿FrameLayout
的底部。
此外,您的按钮正在与其育儿RelativeLayout
的顶部对齐,这就是将它们带到视图顶部的原因。删除RelativeLayout
android: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>