Android初学者:防止admob向上推送内容

2022-01-25 00:00:00 android android-layout java eclipse 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>

推荐答案

你有几个选择.

  1. 将按钮设置为固定大小,而不是依赖于重量.权重使您的按钮占用了可用空间的一小部分.因此,当广告加载时,可用空间会减少,然后您的按钮会变小.

  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.

将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

相关文章