【问题标题】:admob banner not showing in popupadmob 横幅未显示在弹出窗口中
【发布时间】:2017-07-30 22:34:48
【问题描述】:

我想在我的 android 音乐播放器的弹出播放器之后添加一个横幅。在 Android Studio 预览模式下,我没有错误,它运行良好,但没有显示横幅。

<?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);
        }
    });

【问题讨论】:

    标签: android popup admob adsense banner


    【解决方案1】:

    广告未在对话框/弹出窗口中展示的主要原因是横幅广告没有足够的空间(宽度)来展示。 记住广告尺寸:

    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
    

    Source

    因此,由于您使用的是 Banner 广告尺寸,请确保您的弹出窗口的宽度尺寸至少为 320 以启用展示广告。如果您确实有足够的空间并且广告仍然没有显示,则问题可能是填充率问题,这意味着您所在的位置没有可投放的广告。让我知道这是否有帮助

    更新:

    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 studio 中的日志以查看问题是否是横幅大小

    【讨论】:

    • 谢谢娜娜,但还是同样的问题。如您所说,编辑了发布的问题。请看一下。
    • @myads mail 你所做的是设置布局的宽度,这对对话框本身没有任何影响。使用 match_parent 作为宽度并在横向模式下测试它是否有效
    • @myadsmail 是的,布局不是问题。它是对话框主题。查看我的更新答案
    • 我也在我的帖子中添加了我的 MainActivity 代码。请检查一下好吗?
    • 是的,先生,同样没有变化:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多