Android-AdMob将广告设置为“消失”?
我想问,如何为Admob实现AdListner。如果点击了广告,我想让它消失。 我试过了,但没用Android-AdMob将广告设置为“消失”?,android,Android,我想问,如何为Admob实现AdListner。如果点击了广告,我想让它消失。 我试过了,但没用 final AdView ad1 = (AdView) findViewById(R.id.ad1); ad1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method
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(); }
});
谢谢。根据您所在的设备,您可能需要使用该视图的invalidate()方法。(我会注意到我需要在2.1设备上的freewheel上做一些广告) --或--
尝试将ad1视图放置在包装器视图(LinearLayout或其他小视图)中,然后将该包装器视图的可见性设置为view.GONE 我认为AsAdview是相对年轻的,所以你需要
* ad1.setClickable(true);
或
如果仍有人在搜索此文件,以下是我使用的代码:
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
}
}
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
}
}