【问题标题】:Not enough space for displaying AdMob banner(Android)显示 AdMob 横幅的空间不足(Android)
【发布时间】:2014-02-24 14:27:26
【问题描述】:

我在小屏幕上显示 AdMob 横幅时遇到问题(在横向模式下有效)。 在 Galaxy S4 上测试,广告会显示,但仅在横向模式下在小屏幕上显示。我尝试将 xml 布局参数(宽度和高度)更改为 match_parent、wrap_content 和 fill_parent,但还是一样。

错误堆栈跟踪: 02-24 16:30:36.327:W/Ads(396):没有足够的空间来展示广告。需要 320x50 像素,但只有 208x239 像素。

我的 xml 是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@raw/backgroundc"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/buttonGetLuck"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@layout/get_luck_custom_button"
        android:onClick="buttonGetLuck"
        android:text="Get Lucky"
        android:textStyle="italic"
        android:typeface="sans" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="16dp"
        android:text="See your luck for today."
        android:textColor="#7CFC00"
        android:textSize="18sp"
        android:textStyle="italic"
        android:typeface="serif" />

    <LinearLayout
        android:id="@+id/bannerLayuout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:layout_centerHorizontal="true"/>

</RelativeLayout>

我的代码是:

 // Create the adView.
    adView = new AdView(this);
    adView.setAdUnitId("*******");
    adView.setAdSize(AdSize.BANNER);

    // AdMob banner layout
    LinearLayout layout = (LinearLayout)findViewById(R.id.bannerLayuout);

    // Add the adView to it.
    layout.addView(adView);

    // Initiate a generic request.
    AdRequest adRequest = new AdRequest.Builder().build();

    // Load the adView with the ad request.
    adView.loadAd(adRequest);

【问题讨论】:

  • 我也使用 AdSize.SMART_BANNER 进行测试,但仍然无法正常工作...
  • 如果您看不到视图并且您确定它应该在那里。尝试将 ScrollView 添加到父视图。这将允许您查看子视图是否被推离屏幕。我认为这就是您的布局现在的问题
  • ScrollView 没有帮助。横幅的静态尺寸为 320x50,如果设备没有此分辨率,如何将其动态更改为设备支持的分辨率。

标签: android admob banner banner-ads


【解决方案1】:

我认为问题可能是父视图上的“填充”。

尝试删除这些行:

android:paddingLeft="@dimen/activity_horizo​​ntal_margin" android:paddingRight="@dimen/activity_horizo​​ntal_margin"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多