【问题标题】:Resize admob banner to screen size in android studio在android studio中将admob横幅调整为屏幕大小
【发布时间】:2017-02-19 13:23:28
【问题描述】:

我最近开始在我的 Android 应用中使用 admob 横幅广告。它工作得很好,但我有一些问题。至于现在,我使用的是 BANNER,而不是 SMART_BANNER。我的横幅适用于大多数手机,除了一小部分手机。在我的模拟器上,我可以看到横幅对于屏幕来说太大时会出现问题。

我尝试使用智能横幅,但在 logcat 中仍然收到相同的消息:“横幅需要 340x50。只有 288x460”。我的横幅可以在大多数 5 英寸屏幕上工作,除了一些屏幕。但是当我在较小的屏幕尺寸上试用该应用程序时,横幅是不可见的。

所以我的问题是:如何调整横幅大小以适应所有屏幕尺寸?

这是我用来创建广告横幅的代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <android.support.percent.PercentRelativeLayout

        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:id="@+id/timer1background2"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="127dp"
            android:id="@+id/TimerTextview1"
            android:textColor="@android:color/black"
            android:textStyle="normal|bold"
            app:layout_marginTopPercent="11%"
            android:text="APP NAME"
            android:textSize="45dp" />

        <Button
            android:text="Go To Timer 1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:id="@+id/StartB1"
            android:textColor="@android:color/background_light"
            android:background="@color/colorPrimaryDark"
            android:textStyle="normal|bold"
            android:textSize="35sp"
            app:layout_marginTopPercent="33%"
            app:layout_heightPercent="15%"/>

        <Button
            android:text="Go To Timer 2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:id="@+id/StartB2"
            android:textColor="@android:color/background_light"
            android:background="@color/colorPrimaryDark"
            android:textStyle="normal|bold"
            android:textSize="35sp"
            app:layout_marginTopPercent="58%"
            app:layout_heightPercent="15%"/>

    </android.support.percent.PercentRelativeLayout>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="MY KEY">
    </com.google.android.gms.ads.AdView>
</RelativeLayout>

还有:

//Load ads
MobileAds.initialize(getActivity().getApplicationContext(), "MY KEY");

AdView adView = (AdView) myView.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);

【问题讨论】:

    标签: android admob banner screen-size


    【解决方案1】:

    使用具有动态广告尺寸的 SMART_BANNER(屏幕宽度 x 32|50|90)

    将 ads:adSize="BANNER" 替换为 ads:adSize="SMART_BANNER"

    从这里阅读更多信息Banner Ads|Mobile Ads SDK (Android)

    【讨论】:

      【解决方案2】:

      从 google 广告文档中,横幅广告具有特定的尺寸,see here,对于全屏广告,我认为您应该使用插页式广告。 Documented here.

      【讨论】:

      • 可以看到 BANNER 的最小 WxH 为 320x50。那么如果屏幕尺寸比那个小呢?
      • 就是这个比例。如果设备宽度发生变化,广告视图会调整它。
      • 但是当我按照你说的做时,广告没有显示。仅当屏幕有空间时。
      • 此问题已在herehere 讨论。浏览这些链接。
      【解决方案3】:

      常规横幅尺寸固定,您不能扩展它们

      您需要的是充满屏幕宽度的智能横幅

      this

      【讨论】:

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