gpt4 book ai didi

java - AdMob 横幅出现在大屏幕 Android 设备屏幕中央

转载 作者:行者123 更新时间:2023-12-01 16:33:24 25 4
gpt4 key购买 nike

我尝试使用 AdMob 制作 Android 应用。

我按照文档中的描述创建了 admob adView:

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

然后,如果我在 320x480 的设备(手机)上运行我的应用程序,广告横幅将显示在顶部,但如果我在 1280x800 的 Android 平板电脑上运行我的应用程序,广告横幅将水平和垂直居中显示 - 在中心屏幕。

另外,我尝试了 AdSize.BANNER、AdSize.IAB_BANNER、AdSize.IAB_LEADERBOARD - 结果是相同的。

我做错了什么?

UPD1。 res/layout/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>

最佳答案

这应该可以解决问题。

     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);

在 xml 中所做的操作中,您没有指定任何重力。

关于java - AdMob 横幅出现在大屏幕 Android 设备屏幕中央,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12023172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com