gpt4 book ai didi

android - 当方向处于横向模式时,android 中的 Admob SMART_BANNER 不起作用

转载 作者:行者123 更新时间:2023-11-29 01:29:38 24 4
gpt4 key购买 nike

我在我的 Android 应用程序中使用 Admob SMART_BANNER。当设备处于纵向模式时,该应用程序会显示。但是,如果设备方向处于横向模式,则不会显示添加。我知道如果没有足够的空间来显示添加,则不会显示横幅添加。但就我而言,它似乎有足够的空间来显示一个添加。这是我的代码:

activity_main.xml 文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"/>

<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>


</RelativeLayout>

values 文件夹中的 strings.xml 文件:

<resources>
<string name="app_name">Banner Example</string>

<string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>

</resources>

Java代码:

TelephonyManager tManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
String uid = tManager.getDeviceId();

AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder`enter code here`()
.addTestDevice(uid)
.build();
mAdView.loadAd(adRequest);

最佳答案

这可能不适用于原始问题,但我想分享我对 SMART_BANNER 不起作用的情况的解决方案。

我发现在我的例子中,SMART_BANNER 想要占据屏幕的整个宽度,而不管方向是横向还是纵向。我把 AdView 放在底部。如果它位于占屏幕宽度 80% 的列中,则它既不会显示也不会提示(即不调用 onAdFailedToLoad)。它只是隐藏起来。一旦它占据了整个宽度,广告就可以毫无问题地展示。

关于android - 当方向处于横向模式时,android 中的 Admob SMART_BANNER 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31984225/

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