我是 android 编程新手。我已按照说明创建了一个 admob 横幅。我怎样才能让它以一定的间隔出现,如果我想让它消失?例如,admob 横幅可以随时在屏幕底部上下移动。谢谢。
编辑:
我知道我可以调用adView.setVisibility( View.GONE );
以使广告出现和消失,但是当我尝试将其写入线程以使其每隔一段时间出现和消失时,它只是挂在那里并出现黑屏。
或者无论如何admob可以让他们的广告每隔一段时间出现和消失?
这就是我调用线程的方式。
loadAdmob = new asyncAdmobProc();
loadAdmob.execute();
loadAdmob.doInBackground();//asyncAdmobProc();
编码:
//wakes up the admob
private class asyncAdmobProc extends AsyncTask<Integer , Void, Integer> {
private boolean bconthread=true;
protected Integer doInBackground(Integer... Params) {
//wakes up and disable admob
/*AdManager.setTestDevices( new String[] {
AdManager.TEST_EMULATOR, // Android emulator
"E83D20734F72FB3108F104ABC0FFC738", // My T-Mobile G1 Test Phone
} );//*/
adView = (AdView)findViewById(R.id.articleList_ads);
adView.requestFreshAd();
adView.setVisibility( View.GONE );
//while(bconthread){
adView.requestFreshAd();
ShowAd();
postDelayed();
//HideAd();
postDelayed();
//}
//call this to delete all bitmaps associated with the ad
adView.cleanup();
return 0;
}
private void HideAd()
{
// Hide the ad.
adView.setVisibility( View.GONE );
// Fade the ad in over 4/10 of a second.
AlphaAnimation animation = new AlphaAnimation( 0.0f, 1.0f );
animation.setDuration( 400 );
animation.setFillAfter( true );
animation.setInterpolator( new AccelerateInterpolator() );
adView.startAnimation( animation );//*/
}
private void ShowAd()
{
// Unhide the ad.
adView.setVisibility( View.VISIBLE );
// Fade the ad in over 4/10 of a second.
AlphaAnimation animation = new AlphaAnimation( 0.0f, 1.0f );
animation.setDuration( 400 );
animation.setFillAfter( true );
animation.setInterpolator( new AccelerateInterpolator() );
adView.startAnimation( animation );//*/
}
}