我在我的 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>
值文件夹中的 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);