0

我在小屏幕上显示 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);
4

1 回答 1

1

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

尝试删除这些行:

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

于 2014-03-17T18:38:12.090 回答