2017-07-26 81 views
0

我想在我的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); 
     } 
    }); 

回答

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的寬度尺寸,使顯示廣告。如果您確實有足夠的空間並且廣告仍未展示,則問題可能是填充率問題,這意味着您的位置中沒有可投放的廣告。讓我知道,如果這有助於

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工作室,看看問題是否是橫幅大小

+0

謝謝娜娜,但仍然是同樣的問題。像你說的那樣編輯發佈的問題。請看一下。 –

+0

https://ibb.co/dMoraQ ...這是截圖。 –

+0

@myads郵件你所做的是設置佈局的寬度,這對對話框本身沒有任何影響。在寬度模式下使用match_parent並在橫向模式下測試以查看它是否可行 –