简体   繁体   中英

Android Beginner: Prevent admob from pushing content up

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?

Here is my code

<?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>

You have a few options.

  1. 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.

  2. Change your RelativeLayout into a FrameLayout and put the ads after the button LinearLayout.

  3. Put everything inside ScrollView, ie:

RelativeLayout -> ScrollView -> LinearLayout (height:wrap_content,width:fill_parent) -> AdView + LinearLayout with Buttons

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM