2017-09-04 1 views
1

J'utilise des annonces dans mon application, et je l'ai suivi le tutoriel ici: https://developers.google.com/admob/android/bannerAndroid- Smart Ad bannière ne montre pas à l'écran en mode portrait

Si je mets le AdSize juste « BANNIERE » dans le xml, tout fonctionne bien, mais l'annonce n'a pas l'air bien en mode paysage ou sur de plus grands écrans. Alors maintenant j'essaye de changer l'adSize en "SMART_BANNER", mais pour une raison quelconque la bannière est montrée seulement en mode paysage, et sur le portrait j'ai juste une publicité blanche. Qu'est-ce que j'oublie ici?

Voici le code:

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> 

MainActivity.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); 
    }   
} 
+0

S'il vous plaît poster des journaux ici .. Logcat doit avoir enregistré l'exception lancée par Admob ... Il peut être en raison de la mise en page et la hauteur configurations .. –

+0

J'ai essayé d'entourer le ShowLittleAd() avec essayer et attraper, mais je n'ai pas vu d'erreurs – Shayts

+0

dans le logCat, essayez de filtrer pour "annonces". voyez-vous des traces? –

Répondre

1

Okay..I pris le problème ...

S'il vous plaît supprimer toutes les marges de votre annonce. Remplacer cette

<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> 

à cette -

<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> 

Comme bannière prendra largeur maintenant et peut être montré. Le problème était, avec les marges, Il n'obtenait pas assez de largeur pour l'affichage ...

+0

Merci mon pote! Il a résolu le problème :) – Shayts

+0

Glad it helps :) –