如何在广告未显示时填充空白区域

时间:2014-10-20 22:56:14

标签: android-layout admob

我想在广告没有显示在我的应用中时填补空白区域。

广告工作正常,并在我与互联网连接时显示。

但是当手机未连接时,确定广告不会显示

因此广告空间变为空白。

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <com.google.android.gms.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxx"
                     ads:adSize="BANNER"/>
    <TabWidget 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@android:id/tabs"
        />
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

    </FrameLayout>
</LinearLayout>

1 个答案:

答案 0 :(得分:2)

你可以试试这个:

     @Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       AdView adView = (AdView)this.findViewById(R.id.adView);
       AdRequest adRequest = new AdRequest.Builder().build();
      adView.loadAd(adRequest);
      adView.setAdListener(new AdListener() {
      public void onAdFailedToLoad(int errorcode) {}
      adView.setVisibility(View.GONE);
    });
}