【问题标题】:Cannot show Android AdMob无法显示 Android AdMob
【发布时间】:2013-08-18 17:07:22
【问题描述】:

我在我的应用上添加了 admob sdk 6.4,但它未能在应用上显示

logcat 显示以下错误信息

?:??: W/?(?): com.android.internal.widget.SizeAdaptiveLayout@425f9e70child view android.widget.FrameLayout@424d1538 在 95px 被限制到 96px 时测量出界

而我的activity_mail.xml如下

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ns="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
    android:id="@+id/picture"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/sexy" >
</ImageView>

<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#00000000"
    android:stretchColumns="*" >
</TableLayout>

<TableRow
    android:id="@+id/tableRow1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_margin="3sp"
    android:layout_marginBottom="116dp"
    android:gravity="center"
    android:weightSum="2" >

    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Pattern #1" />

    <Button
        android:id="@+id/btn2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Pattern #2" />

    <Button
        android:id="@+id/btn3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="OFF" />
</TableRow>

<com.google.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/tableRow1"
    ns:adSize="BANNER"
    ns:adUnitId="a152106a3311446 "
    ads:testDevices="37329DE7326D00EC" >
</com.google.ads.AdView>
</RelativeLayout>

我该如何解决?

【问题讨论】:

  • 你把罐子放进去了吗?
  • 我将它包含在构建路径中(外部 jars)
  • 你的库文件夹是“lib”还是“libs”?

标签: android view admob


【解决方案1】:

将标签放在里面,因为 TableLayout 是 TableLayout 的父级并使用 android:layout_alignParentBottom="true" 属性。

<TableLayout
    android:id="@+id/tableLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:background="#00000000"
    android:stretchColumns="*" >

<TableRow
    android:id="@+id/tableRow1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:weightSum="2" >

    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Pattern #1" />

    <Button
        android:id="@+id/btn2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Pattern #2" />

    <Button
        android:id="@+id/btn3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="OFF" />
</TableRow>
</TableLayout>

<com.google.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/tableLayout"
    ns:adSize="BANNER"
    ns:adUnitId="a152106a3311446 "
    ads:testDevices="37329DE7326D00EC" >
</com.google.ads.AdView>

【讨论】:

    【解决方案2】:

    我不知道这是否会导致您的问题,但在您的 AdView 中,您必须声明

       android:layout_above="@id/tableRow1"
    

    但你有

       android:layout_above="@+id/tableRow1" <--the + is wrong
    

    第二个是您的 adUnitId 末尾有一个空白(顺便说一下,不要在 stackoverflow 中显示您的真实 ID)

    【讨论】:

      猜你喜欢
      • 2016-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-01
      相关资源
      最近更新 更多