2012-06-15 56 views
2

我想問一下,如何實施Admob的AdListner。如果點擊廣告,我希望廣告能夠消失。 我試過了,但沒有幫助。Android - AdMob將Ads設置爲GONE?

final AdView ad1 = (AdView) findViewById(R.id.ad1); 
     ad1.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       ad1.setVisibility(View.GONE); 
       ad1.destroy();   } 
     }); 

謝謝。

回答

0

如果有人仍在尋找這一點,這裏是我使用的代碼:

public class myActivity extends Activity implements AdListener{ 
    /** Called when the activity is first created. */ 


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 


     AdView adView = (AdView)this.findViewById(R.id.ads2); 
     adView.setAdListener(this); 
     adView.loadAd(new AdRequest()); 





    } 

    public void onDismissScreen(Ad arg0) { 
     RelativeLayout rellayout = (RelativeLayout) findViewById(R.id.rellayout); 
     AdView adView = (AdView)this.findViewById(R.id.ads2); 
     rellayout.removeView(adView); 
    } 

    public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) { 
     // TODO Auto-generated method stub 

    } 

    public void onLeaveApplication(Ad arg0) { 
     // TODO Auto-generated method stub 

    } 

    public void onPresentScreen(Ad arg0) { 
     // TODO Auto-generated method stub 

    } 

    public void onReceiveAd(Ad arg0) { 
     // TODO Auto-generated method stub 

    } 

} 
1

根據您所在的設備,您可能需要使用該視圖的invalidate()方法。 (我會注意到我需要在2.1設備上使用自由輪播放一些廣告內容)。

- 或 - 嘗試將ad1視圖放在包裝視圖(LinearLayout或其他小視圖)中,然後將該包裝視圖的可見性設置爲View.GONE。

1

我覺得作爲AdView的是RelativeLayout的,所以你需要

* ad1.setClickable(true); 

* can put entry in layout XML `android:clickable="true"` 

enter image description here