android - 如何正确安装 admob,在某些测试手机上不显示

标签 android admob android-xml

我需要一个关于如何在我的应用程序中正确安装 andmob 的清晰示例,非常令人费解,我能够弄清楚我认为最困难的部分是针对 3.2 进行编译并将最小 sdk 设置为 7是我想要定位的最小 SDK。

不过

我现在发现我可以让它在我的 galaxy note 上运行,但是在我的 lg optimus one 和 galaxy apollo 上分别是 android 2.1 和 2.2,这两款手机都没有运行广告,不太确定这有什么意义,我还发现 admob 文档非常困惑和不清楚,我将其解释为开发人员可以使用纯 xml 或纯 java 代码来执行此操作,我使用纯 xml 这里是我的代码广告 list

<activity
        android:name="com.google.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

编辑:布局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/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/title_color_dark" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:layout_marginTop="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:orientation="vertical"
    android:paddingTop="8dp" >

    <TextView
        android:id="@+id/saysomething"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/loading"
        android:textColor="#FFFFFF"
        android:textSize="30dp" />

    <TextView
        android:id="@+id/saysomethinginfo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:text="@string/loading"
        android:textColor="#FFFFFF"
        android:textSize="17dp" />

    <EditText
        android:id="@+id/tweetedittext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/edit_text"
        android:gravity="top"
        android:hint="@string/edittext_hint"
            android:inputType="textCapSentences|textMultiLine|textAutoCorrect|textAutoComplete"
        android:lines="4"
        android:textAppearance="@style/TextAppearance.EditText" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:gravity="right"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/charactersremaining"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/characters"
            android:textColor="#FFFFFF"
            android:textSize="20dp" />

        <Button
            android:id="@+id/posttweetbutton"
            style="@style/TextAppearance.Button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:background="@drawable/button_background"
            android:onClick="posttweetbuttonClicked"
            android:text="@string/postbuttonstext"
            android:textSize="15dp" />
    </LinearLayout>

    <com.google.ads.AdView
        android:layout_marginTop="8dp"
        android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="a14f5be094d0328"
        ads:loadAdOnCreate="true" />
</LinearLayout>

修改2个新版布局,让dialog activity占满整个屏幕但仍然不显示广告

<?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="@color/title_color_dark" >

<LinearLayout
    android:layout_alignParentTop="true"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="8dp"
    android:orientation="vertical"
    android:paddingTop="8dp" >

    <TextView
        android:id="@+id/saysomething"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/loading"
        android:textColor="#FFFFFF"
        android:textSize="30dp" />

    <TextView
        android:id="@+id/saysomethinginfo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:text="@string/loading"
        android:textColor="#FFFFFF"
        android:textSize="17dp" />

    <EditText
        android:id="@+id/tweetedittext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/edit_text"
        android:gravity="top"
        android:hint="@string/edittext_hint"
        android:inputType="textCapSentences|textMultiLine|textAutoCorrect|textAutoComplete"
        android:lines="4"
        android:textAppearance="@style/TextAppearance.EditText" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:gravity="right"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/charactersremaining"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/characters"
            android:textColor="#FFFFFF"
            android:textSize="20dp" />

        <Button
            android:id="@+id/posttweetbutton"
            style="@style/TextAppearance.Button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:background="@drawable/button_background"
            android:onClick="posttweetbuttonClicked"
            android:text="@string/postbuttonstext"
            android:textSize="15dp" />
    </LinearLayout>
</LinearLayout>


<com.google.ads.AdView
    android:id="@+id/adView"
    android:layout_alignParentBottom="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"        
    ads:adSize="BANNER"
    ads:adUnitId="a14f5be094d0328"
    ads:loadAdOnCreate="true" />

edit 3 使用所有线性布局,两侧没有任何边距,但仍不产生广告

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="@color/title_color_dark" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="8dp"
    android:orientation="vertical"
    android:paddingTop="8dp" >

    <TextView
        android:id="@+id/saysomething"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/loading"
        android:textColor="#FFFFFF"
        android:textSize="30dp" />

    <TextView
        android:id="@+id/saysomethinginfo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:text="@string/loading"
        android:textColor="#FFFFFF"
        android:textSize="17dp" />

    <EditText
        android:id="@+id/tweetedittext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/edit_text"
        android:gravity="top"
        android:hint="@string/edittext_hint"
            android:inputType="textCapSentences|textMultiLine|textAutoCorrect|textAutoComplete"
        android:lines="4"
        android:textAppearance="@style/TextAppearance.EditText" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:gravity="right"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/charactersremaining"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/characters"
            android:textColor="#FFFFFF"
            android:textSize="20dp" />

        <Button
            android:id="@+id/posttweetbutton"
            style="@style/TextAppearance.Button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:background="@drawable/button_background"
            android:onClick="posttweetbuttonClicked"
            android:text="@string/postbuttonstext"
            android:textSize="15dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="8dp"
        android:orientation="vertical" >

        <com.google.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adSize="BANNER"
            ads:adUnitId="a14f5be094d0328"
            ads:loadAdOnCreate="true" />
    </LinearLayout>
</LinearLayout>

</LinearLayout>

最佳答案

AdView 的宽度为 320dp,这是大多数纵向模式手机屏幕的整个宽度。 AdView 位于带有 android:layout_marginLeft="8dp"的 LinearLayout 内 android:layout_marginRight="8dp" 因此它没有足够的宽度来展示广告。

如果你检查你的日志,可能会有这样的警告:

没有足够的空间显示广告!想要:480、75,拥有:456、75

要解决此问题,您需要移除顶层布局的边距,或者将 AdView 移到顶层 LinearLayout 之外。

关于android - 如何正确安装 admob,在某些测试手机上不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9688795/

相关文章:

unity-game-engine - AdMob 在游戏对象上统一展示广告

java - layout_width/height 如何与最小/最大宽度/高度一起使用

android - 以编程方式使状态栏不透明

android - ViewPager 显示 fragment 的问题

android - 插屏广告后Exoplayer播放错误

java - 插入后获取生成的id

silverlight - 错误: You cannot call webbrowser methods until it is in the visual tree

java - 布局更改时字符串值不会更改

android - 在播放之前如何在Android中获取音频文件的幅度?

android - <compatible-screens> 适用于 galaxy note