首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何获取Nativescript-plugin SMART_BANNER高度

如何获取Nativescript-plugin SMART_BANNER高度
EN

Stack Overflow用户
提问于 2020-07-22 16:26:11
回答 1查看 62关注 0票数 0

Nativescript Firebase插件有Admob,您可以使用智能横幅,但我们不能检测横幅的高度。在不同屏幕大小上加载横幅后,我能得到谁的横幅高度?

代码语言:javascript
复制
  firebase.admob.showBanner({
    size: firebase.admob.AD_SIZE.SMART_BANNER, // see firebase.admob.AD_SIZE for all options
    margins: { // optional nr of device independent pixels from the top or bottom (don't set both)
      bottom: 10,
      top: -1
    },
    androidBannerId: "ca-app-pub-9517346003011652/7749101329",
    iosBannerId: "ca-app-pub-9517346003011652/3985369721",
    testing: true, // when not running in production set this to true, Google doesn't like it any other way
    iosTestDeviceIds: [ //Android automatically adds the connected device as test device with testing:true, iOS does not
        "45d77bf513dfabc2949ba053da83c0c7b7e87715", // Eddy's iPhone 6s
        "fee4cf319a242eab4701543e4c16db89c722731f"  // Eddy's iPad Pro
    ],
    keywords: ["keyword1", "keyword2"], // add keywords for ad targeting
    onOpened: () => console.log("Ad opened"),
    onClicked: () => console.log("Ad clicked"),
    onLeftApplication: () => console.log("Ad left application")
  }).then(
      function () {
        console.log("AdMob banner showing");
      },
      function (errorMessage) {
        dialogs.alert({
          title: "AdMob error",
          message: errorMessage,
          okButtonText: "Hmmkay"
        });
      }
  );
EN

回答 1

Stack Overflow用户

发布于 2020-07-22 16:26:11

,我们先得到屏幕大小,然后用SMART_BANNER逻辑进行计算。

导入这个平台

代码语言:javascript
复制
const platform = require("platform") 

高度除以比例

代码语言:javascript
复制
const screenHeightDp =platform.screen.mainScreen.heightPixels / platform.screen.mainScreen.scale;

将计算作为智能横幅工作。

代码语言:javascript
复制
const BannerHeight = screenHeightDp > 720 ? 90 : screenHeightDp > 400 ? 50 : 32;

这是我们的旗帜高度

代码语言:javascript
复制
console.log(BannerHeight); 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63038889

复制
相关文章

相似问题

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