admob横幅不显示在弹出
问题描述:
我想在我的android音乐播放器弹出播放器后添加一个横幅。在Android Studio预览模式下,我没有错误,它运行良好,但横幅未显示。admob横幅不显示在弹出
<?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我的代码是正确的我想,因为我试图把横幅在其他屏幕,它工作正常。有什么方法可以将横幅放在弹出屏幕中吗?
我在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);
}
});
答
在对话框不显示广告的主要理由/弹出窗口是由于横幅广告没有得到足够的空间(宽度)来显示。 记住广告尺寸:
320x50 Standard Banner Phones and Tablets BANNER
320x100 Large Banner Phones and Tablets LARGE_BANNER
300x250 IAB Medium Rectangle Phones and Tablets MEDIUM_RECTANGLE
468x60 IAB Full-Size Banner Tablets FULL_BANNER
728x90 IAB Leaderboard Tablets LEADERBOARD
Screen width x 32|50|90 Smart Banner Phones and Tablets SMART_BANNER
那么既然你使用的Banner
广告尺寸,请确保您弹出有至少320的宽度尺寸,使显示广告。如果您确实有足够的空间并且广告仍未展示,则问题可能是填充率问题,这意味着您的位置中没有可投放的广告。让我知道,如果这有助于
UPDATE:
在onCreate()
方法,你可以设置对话框的宽度,以覆盖设备屏幕的全宽:
DisplayMetrics metrics = getResources().getDisplayMetrics();
// int screenWidth = (int) (metrics.widthPixels * 0.99); //99 percent
boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
if(isLandscape)
getWindow().setLayout((int) (metrics.widthPixels * 0.70), ViewGroup.LayoutParams.WRAP_CONTENT);
else getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
您可随时查询登录Android工作室,看看问题是否是横幅大小
谢谢娜娜,但仍然是同样的问题。像你说的那样编辑发布的问题。请看一下。 –
https://ibb.co/dMoraQ ...这是截图。 –
@myads邮件你所做的是设置布局的宽度,这对对话框本身没有任何影响。在宽度模式下使用match_parent并在横向模式下测试以查看它是否可行 –