Android-智能横幅广告在纵向模式下不显示在屏幕上

标签 android admob

我在我的应用程序中使用广告,并且我已按照此处的教程进行操作:https://developers.google.com/admob/android/banner

如果我在 xml 中将 adSize 设置为“BANNER”,一切正常,但广告在横向模式或大屏幕上看起来不太好。所以现在我正在尝试将 adSize 更改为“SMART_BANNER”,但出于某种原因,横幅仅在横向模式下显示,而在纵向模式下我只有一个白色的广告 View 。我在这里缺少什么?

代码如下:

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>


<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="0dp"
    android:padding="0dp"
    tools:context="com.example.shaytsabar.footballtables
    .activities.MainActivity"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="81dp"
    android:layout_marginLeft="0dp">


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar_con"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_margin="0dp"
    android:elevation="0dp"
    android:minHeight="?attr/actionBarSize"
    android:padding="0dp"
    android:paddingBottom="0dp"
    android:paddingEnd="0dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingStart="0dp"
    android:paddingTop="0dp"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />


<com.google.android.gms.ads.AdView 
 xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginStart="8dp"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="@string/ad_id"
    ads:layout_constraintBottom_toBottomOf="parent"
    ads:layout_constraintLeft_toLeftOf="parent"
    ads:layout_constraintRight_toRightOf="parent">
</com.google.android.gms.ads.AdView>

<FrameLayout
    android:id="@+id/fragment_con"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginBottom="8dp"
    android:elevation="0dp"
    android:padding="0dp"
    app:layout_constraintBottom_toTopOf="@+id/adView"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/toolbar_con"
    app:layout_constraintVertical_bias="0.0">

  </FrameLayout>
</android.support.constraint.ConstraintLayout>

主要 Activity .java:

public class MainActivity extends AppCompatActivity{
    InterstitialAd mInterstitialAd;
    AdView mAdView;

   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MobileAds.initialize(this, APPCODE);
        ShowLittleAd();
        mAdView.setAdListener(new AdListener() {
            @Override
            public void onAdFailedToLoad(int i) {
                super.onAdFailedToLoad(i);
                ShowLittleAd();
            }
        });
      }
    public void ShowLittleAd(){
        mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new 
      AdRequest.Builder().addTestDevice("//MY DEVICE").
                addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
        mAdView.loadAd(adRequest);
    }          
}

最佳答案

好的..我发现了问题...

请从您的 Adview 中删除所有边距。 替换这个

<com.google.android.gms.ads.AdView 
 xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginStart="8dp"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="@string/ad_id"
    ads:layout_constraintBottom_toBottomOf="parent"
    ads:layout_constraintLeft_toLeftOf="parent"
    ads:layout_constraintRight_toRightOf="parent">
</com.google.android.gms.ads.AdView>

为此-

<com.google.android.gms.ads.AdView 
 xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="@string/ad_id"
    ads:layout_constraintBottom_toBottomOf="parent"
    ads:layout_constraintLeft_toLeftOf="parent"
    ads:layout_constraintRight_toRightOf="parent">
</com.google.android.gms.ads.AdView>

因为横幅现在将占据全宽并且可以显示。问题是,对于边距,它没有足够的宽度来显示......

关于Android-智能横幅广告在纵向模式下不显示在屏幕上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46034018/

相关文章:

android - 如何在 mvvm android 中显示对话框

java - Android Studio 模拟器 "won' t 运行,除非您更新 Google Play 服务”

ios - AdMob 只发送真实广告,而不发送测试广告,为什么?

java - RecyclerView 中的 Admob 原生广告

android - AdMob 广告在 ListView 中需要点击两次才能激活?

android - admob 将区域设置重置为默认值

Android - 将 ImageView 动态添加到 ScrollView

android - 转换Android strings.xml文件的最简单方法

android - 使用 OkHttp 检查套接字是否连接或断开连接的更好方法?

android - 由于 Admob 广告,Recyclerview 在滚动时滞后