我尝试在页面底部设置AdMob横幅,但广告未显示。 空格显示在页面的底部,但AdMob不显示在那里。
有人告诉我原因。 谢谢。
我的XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/flContainer" <!-- DATA Layout -->
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/ad_layout"
android:orientation="vertical" />
<LinearLayout
android:id="@+id/ad_layout" <!-- AdMob Layout -->
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:orientation="vertical" />
</RelativeLayout>
MainActivity.java
// Create an ad.
adView = new AdView(context);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);
// Add the AdView to the view hierarchy. The view
// will have no size
// until the ad is loaded.
LinearLayout layout = (LinearLayout) findViewById(R.id.ad_layout);
//layout.getBottom();
layout.addView(adView);
// Create an ad request. Check logcat output for the
// hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE").build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
答案 0 :(得分:0)
你告诉fieldContainer match_Parent。这意味着它将消耗父级的所有空间,而不会为您的广告留下任何空间。
而是尝试:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/flContainer" <!-- DATA Layout -->
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" />
<LinearLayout
android:id="@+id/ad_layout" <!-- AdMob Layout -->
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical" />
</LinearLayout>