首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在android studio中将admob横幅调整为屏幕大小

在android studio中将admob横幅调整为屏幕大小
EN

Stack Overflow用户
提问于 2017-02-19 21:23:29
回答 3查看 5.5K关注 0票数 2

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

我尝试使用智能横幅,但在logcat中仍然得到相同的信息:“横幅需要340x50.只有288x460”。我的横幅在大多数5英寸屏幕上都能用,但当我在较小的屏幕上试用时,横幅就看不见了。

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

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

代码语言:javascript
复制
<?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>

和:

代码语言:javascript
复制
//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);
EN

回答 3

Stack Overflow用户

发布于 2019-01-17 07:31:35

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

用ads:adSize="SMART_BANNER"替换ads:adSize="BANNER"

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

票数 3
EN

Stack Overflow用户

发布于 2017-02-19 21:32:00

根据谷歌的广告文档,横幅广告有特定的大小,see here,对于全屏广告,我认为你应该使用间隙广告。Documented here

票数 0
EN

Stack Overflow用户

发布于 2017-02-21 00:52:35

常规横幅有固定大小,您不能扩展它们

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

看看this

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42327730

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档