我放了一个退出按钮,如果点击广告就可以取消广告,但我希望在广告出现时显示此按钮,并在广告消失时消失。我怎样才能做到这一点? 这是我退出广告的代码:
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 :(得分:0)
尝试这种方式:
AdView adView = (AdView)this.findViewById(R.id.adView1); adView.setVisibility(View.INVISIBLE);