简体   繁体   English

在大屏幕android设备上,AdMob横幅显示在屏幕中央

[英]AdMob banner appears on the screen at the center on large screen android devices

I try to make android app with AdMob. 我尝试使用AdMob制作android应用。

I create the admob adView as described in documentation: 我按照文档中所述创建admob adView:

FrameLayout layout = (FrameLayout) findViewById(R.id.frame_layout);
adView = new AdView(this, AdSize.SMART_BANNER, myAdMobId );

Then, if I run my app on a device 320x480 (phone), the advert banner appears on the top, but if I run my app on a android tablet 1280x800, the advert banner appears centered horizontally and vertically - at the center of screen. 然后,如果我在设备320x480(电话)上运行我的应用程序,则广告横幅会显示在顶部,但如果我在Android平板电脑1280x800上运行我的应用程序,则广告横幅会在水平和垂直方向居中显示-在屏幕中央。

Also, I tried AdSize.BANNER, AdSize.IAB_BANNER, AdSize.IAB_LEADERBOARD - result is the same. 另外,我尝试了AdSize.BANNER,AdSize.IAB_BANNER,AdSize.IAB_LEADERBOARD-结果是相同的。

What I am doing wrong? 我做错了什么?

UPD1. UPD1。 res/layout/main.xml RES /布局/ main.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frame_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
<com.mysite.myapp.GameView
      android:id="@+id/game"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"/>    
</FrameLayout>

This should do the trick. 这应该可以解决问题。

     FrameLayout.LayoutParams adsParams =new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, 
            FrameLayout.LayoutParams.WRAP_CONTENT, android.view.Gravity.TOP|android.view.Gravity.CENTER_HORIZONTAL); 

    layout.addView(adView, adsParams);

in what you did in the xml, you didn't specify any gravity. 在xml中所做的操作中,您没有指定任何重力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM