Android Beginner: Prevent admob from pushing content up(Android初学者:防止admob向上推送内容)
问题描述
我是初学者,请耐心等待.我有一个带有几个按钮的布局,然后在底部有一个 adview.当广告加载时,它会向上推动按钮并使它们变得非常小.有没有办法防止内容被推上去?
I am a beginner so bear with me. I have a layout with several buttons and then an adview at the bottom. When the ad loads, it pushes the buttons up and makes them very small. Is there anyway to prevent the content from being pushed up?
这是我的代码
<?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:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_hdpi" >
<com.google.ads.AdView
android:id="@+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="a14fc541226f07b"
ads:loadAdOnCreate="true" >
</com.google.ads.AdView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/ad"
android:orientation="vertical"
android:weightSum="7.0" >
<Button
android:id="@+id/basics1"
android:layout_width="150.0dip"
android:layout_height="0.0dip"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="2.0dip"
android:layout_marginTop="100.0dip"
android:layout_weight="1.0"
android:text="Overview"
android:textSize="16.0sp" />
<Button
android:id="@+id/basics2"
android:layout_width="150.0dip"
android:layout_height="0.0dip"
android:layout_gravity="center_horizontal"
android:layout_margin="2.0dip"
android:layout_weight="1.0"
android:text="Campaign"
android:textSize="16.0sp" />
<Button
android:id="@+id/basics3"
android:layout_width="150.0dip"
android:layout_height="0.0dip"
android:layout_gravity="center"
android:layout_margin="2.0dip"
android:layout_weight="1.0"
android:text="Special Ops"
android:textColor="#ff000000"
android:textSize="16.0sp" />
<Button
android:id="@+id/basics4"
android:layout_width="150.0dip"
android:layout_height="0.0dip"
android:layout_gravity="center_horizontal"
android:layout_margin="2.0dip"
android:layout_weight="1.0"
android:text="Zombies"
android:textColor="#ff000000"
android:textSize="16.0sp" />
<Button
android:id="@+id/basics5"
android:layout_width="150.0dip"
android:layout_height="0.0dip"
android:layout_gravity="center_horizontal"
android:layout_margin="2.0dip"
android:layout_weight="1.0"
android:text="Modes"
android:textColor="#ff000000"
android:textSize="16.0sp" />
<Button
android:id="@+id/basics6"
android:layout_width="150.0dip"
android:layout_height="0.0dip"
android:layout_gravity="center_horizontal"
android:layout_margin="2.0dip"
android:layout_weight="1.0"
android:text="Ranks/Unlocks"
android:textColor="#ff000000"
android:textSize="16.0sp" />
</LinearLayout>
</RelativeLayout>
推荐答案
你有几个选择.
将按钮设置为固定大小,而不是依赖于重量.权重使您的按钮占用了可用空间的一小部分.因此,当广告加载时,可用空间会减少,然后您的按钮会变小.
Make your buttons a fixed size instead of weight dependent. Weights make your Buttons take up a fraction of the space available. So when the ad loads, the space available decreases and then your buttons become smaller.
将RelativeLayout 更改为FrameLayout 并将广告放在LinearLayout 按钮之后.
Change your RelativeLayout into a FrameLayout and put the ads after the button LinearLayout.
把所有东西都放到ScrollView里面,即:
Put everything inside ScrollView, ie:
RelativeLayout -> ScrollView -> LinearLayout (height:wrap_content,width:fill_parent) -> AdView + LinearLayout with Buttons
RelativeLayout -> ScrollView -> LinearLayout (height:wrap_content,width:fill_parent) -> AdView + LinearLayout with Buttons
这篇关于Android初学者:防止admob向上推送内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android初学者:防止admob向上推送内容


- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 转换 ldap 日期 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 获取数字的最后一位 2022-01-01