在Android工作室

时间:2017-02-19 13:23:29

标签: android admob banner screen-size

我最近开始在我的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);

3 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

常规横幅有固定大小,你无法扩展它们

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

查看this

答案 2 :(得分:0)

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

SMART_BANNER

按广告:adSize = “ SMART_BANNER”

替换广告:adSize = “横幅”

从此处了解更多信息Banner Ads|Mobile Ads SDK (Android)