Admob不会在所有设备中显示横幅

时间:2014-07-28 15:17:04

标签: android xml android-layout admob

我已经构建了这个main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background"
    android:clipToPadding="true"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="true"
        android:orientation="vertical"
        android:paddingBottom="@dimen/Space075"
        android:paddingLeft="@dimen/Space075"
        android:paddingRight="@dimen/Space075" >

        <!-- start no_account_page -->

        <include layout="@layout/no_account_page" />

        <!-- end  no_account_page -->

        <RelativeLayout
            android:id="@+id/content_accounts_present"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/Space200"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/AppLogo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/big_padlock" />

            <TextView
                android:id="@+id/SH5Are"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:layout_marginLeft="@dimen/Space100"
                android:layout_toRightOf="@+id/AppLogo"
                android:text="@string/SH5Are"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="@color/DarkRed"
                android:textSize="@dimen/text075" />

            <TextView
                android:id="@+id/ProtectingYou"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/SH5Are"
                android:layout_below="@+id/SH5Are"
                android:layout_marginTop="@dimen/SpaceMinus050"
                android:text="@string/ProtectingYou"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="@color/DarkRed"
                android:textSize="@dimen/text100" />

            <TextView
                android:id="@+id/VerificationCodeList"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/ProtectingYou"
                android:layout_alignParentRight="true"
                android:layout_below="@+id/ProtectingYou"
                android:paddingBottom="@dimen/Space150"
                android:text="@string/VerificationCodeList"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="@color/Black"
                android:textSize="@dimen/text075" />
        </RelativeLayout>

        <ListView
            android:id="@+id/user_list"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:gravity="center|top"
            android:orientation="vertical"
            android:textColor="@color/Black" />
    </LinearLayout>

    <include layout="@layout/admob_banner" />

</LinearLayout>

这是admob_banner.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:layout_weight="2">

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        ads:adSize="BANNER"
        ads:adUnitId="THIS_IS_MY_ID" />

</LinearLayout>
然而,在某些设备中(我尝试过3.2英寸和5英寸的设备,第一个使用Android 2.3,第二个使用4.3),横幅未显示。在我的手机(带有Android 4.1的4.5英寸)中,横幅显示但不在页面底部。 我要疯了。我的错误是什么?为什么有时出现,有时候不?为什么不出现在页面底部?有人可以帮我吗?感谢。

1 个答案:

答案 0 :(得分:0)

您的广告有时可能无法加载,但布局:

<RelativeLayout ...> //outermost layout


<include layout="@layout/admob_banner" 
    android:id="@+id/banner"
    android:layout_alignParentBottom="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/banner">
//The rest of your layout
</LinearLayout>

</RelativeLayout>

并删除Banner的父布局上的权重。实际上,你甚至根本不需要横幅的父LinearLayout