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向上推送内容


基础教程推荐
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- Java Swing计时器未清除 2022-01-01