2013-01-04 62 views
0

我放了一個退出按鈕,如果它的點擊可以消除廣告,但我想讓這個按鈕出現在廣告出現時消失,當廣告消失時消失。我怎樣才能做到這一點? 這是我的代碼退出廣告:如何在出現admob廣告時顯示退出按鈕?

Button exit = (Button) findViewById(R.id.button1); 
     exit.setOnClickListener(new Button.OnClickListener() { 
      public void onClick(View v) { 


       LinearLayout adscontainer = (LinearLayout) findViewById(R.id.Ll); 

       View admobAds = (View) findViewById(R.id.adView1); 

       adscontainer.removeView(admobAds); 

      } 
     }); 

這是XML文件:

<Button 
     android:id="@+id/button1" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:background="@drawable/exit" /> 

<com.google.ads.AdView 
     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:id="@+id/adView1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    ads:adSize="BANNER" 
     ads:adUnitId="a150ce9a2bd8" 
     android:layout_column="0" 
     android:layout_span="3" 
     /> 

回答

0

嘗試這個辦法:

AdView adView = (AdView)this.findViewById(R.id.adView1); 
    adView.setVisibility(View.INVISIBLE); 
+0

感謝您的幫助,但我的代碼關閉廣告是有效的。當廣告出現時,我需要使代碼顯示退出按鈕,並在廣告消失時消失。你可以幫幫我嗎? –