我想在我的Android音乐播放器的弹出播放器之后添加一个 Banner . 在Android工作室预览模式中,我没有错误,它运行正常但 Banner 未显示 .
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="320dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1.0">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primary"
android:paddingBottom="5dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="20dp">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:maxLines="5"
android:textColor="@color/white"
android:textSize="@dimen/text_medium"
tools:text="Mr.Afghani" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/name"
android:gravity="center_vertical">
<ImageView
android:id="@+id/play"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="6"
android:src="@mipmap/play" />
<ImageView
android:id="@+id/pause"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="6"
android:src="@mipmap/pause"
android:visibility="gone" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.8"
android:paddingEnd="10dp"
android:paddingRight="10dp">
<SeekBar
android:id="@+id/media_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
<TextView
android:id="@+id/playback_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|top"
android:ellipsize="end"
android:textColor="@color/white"
android:textSize="11sp"
tools:text="00:00" />
</FrameLayout>
</LinearLayout>
</RelativeLayout>
<com.google.android.gms.ads.AdView
android:id="@id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/bannerAd1" />
</LinearLayout>
在mainActivity我的代码是正确的,我想因为我尝试在其他屏幕上放 Banner ,它工作正常 . 有没有办法在弹出屏幕上放置 Banner ?
我在MainActivity中的代码是:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
init();
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest request = new AdRequest.Builder().build();
mAdView.loadAd(request);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-1234");
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
AdRequest adRequest1 = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest1);
}
});
1 回答
广告未在对话框/弹出窗口中显示的主要原因是 Banner 广告没有获得足够的空间(宽度)来展示 . 请记住广告尺寸:
Source
因此,由于您使用的是
Banner
广告尺寸,因此请确保弹出广告的宽度至少为320,以便能够展示广告 . 如果您确实有足够的空间且广告仍然无法在您所在的位置投放广告't show, the problem could be a fill rate issue, meaning there' . 如果这有帮助,请告诉我UPDATE:
在
onCreate()
方法中,您可以设置对话框的宽度以覆盖设备屏幕的全宽:你总是可以检查android studio中的日志,看看问题是否是 Banner 大小