2016-05-22 11 views
-1

theseは、おそらく私のアンドロイドプロジェクトに広告を挿入(テスト)するための古い手順に従っています。仮想Nexus 5端末でプロジェクトを再コンパイルした後、アプリは動作しますが、追加バナーは表示されません。アンドロイドプロジェクトの広告は表示されません

レイアウトファイルがサンプルレイアウトファイルのように見えないため、レイアウトファイルに問題がある可能性があります。ここでは広告バナーが含まれるように、私のレイアウトファイルの関連する部分です:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    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" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context=".MainActivity" > 

    <android.support.design.widget.AppBarLayout 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary"/> 

    </android.support.design.widget.AppBarLayout> 

    <LinearLayout 
     ... 
     ... 


     <com.google.android.gms.ads.AdView 
      android:id="@+id/adView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_alignParentBottom="true" 
      ads:adSize="BANNER" 
      ads:adUnitId="@string/banner_ad_unit_id"> 
     </com.google.android.gms.ads.AdView> 
    </LinearLayout> 

</android.support.design.widget.CoordinatorLayout> 

は、レイアウトに関連する問題ですか?広告バナーが表示されない理由を理解するにはどうすればよいですか?

+0

LinearLayout内でAdViewのRelativeLayout属性を使用しています。これは問題ではありませんが、AdViewを通常のViewレイアウトに置き換えて、適切に表示されているかどうかを確認する必要があります。 – adelphus

答えて

1

OPとの議論では、それは、のLinearLayout内CoordinatorLayoutとAdViewは両方だったことが判明しましたCoordinatorLayoutは高さが「match_parent」であるため、AdViewを画面から外していました

CoordinatorLayoutの高さを0dpに変更し、ウェイトを1にすると、画面全体を撮影するのではなく、AdViewの上にある残りの領域を埋めるようになります。

android:layout_height="0dp" 
android:layout_weight="1" 
1

は、私はあなたが使用する必要があると思う:

xmlns:ads="http://schemas.android.com/apk/res-auto" 

の代わりに:

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
+0

いいえ、仮想Nexusデバイスを再コンパイルして再起動しても広告は表示されません。 – Alex

+0

@Alex Hmm ... 'CoordinatorLayout'を使用しているので、' LinearLayout'に正しいレイアウト動作が指定されています'AppBarLayout'の下に隠れませんか? –

+0

正しいレイアウト動作は何ですか?私は知らない。私はアンドロイドの初心者です。 – Alex

関連する問題