Admob的android系统中。如何使它出现和消失 [英] Admob in android. How to make it appear and disappear

查看:161
本文介绍了Admob的android系统中。如何使它出现和消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来编程机器人。我按照指示,并创建一个AdMob的横幅。我怎样才能使它出现在一定的时间间隔,并使它消失,如果我想?例如admob的横幅罐上升和下降在每当它想要在屏幕的底部。 谢谢你。

编辑:

我知道,我可以叫 adView.setVisibility(View.GONE); ,使广告出现和消失,但是当我尝试它被写入到一个线程来使它看起来和间隔消失,它只是挂在那儿有一个黑色的屏幕。

或者是有反正是AdMob的可以使自己的广告出现和消失的时间间隔?

这是我如何调用线程。

  loadAdmob =新asyncAdmobProc();
loadAdmob.execute();
loadAdmob.doInBackground(); // asyncAdmobProc();
 

在code:

  //醒来的AdMob的
私有类asyncAdmobProc扩展的AsyncTask<整数,太虚,整数GT; {

    私人布尔bconthread = TRUE;
    保护整数doInBackground(整数... PARAMS){
        //被唤醒并禁止AdMob的

        /*AdManager.setTestDevices(新的String [] {
                AdManager.TEST_EMULATOR,// Android模拟器
                E83D20734F72FB3108F104ABC0FFC738,//我的T-Mobile G1的测试电话
                }); // * /

        AD浏览报=(AD浏览报)findViewById(R.id.articleList_ads);
        adView.requestFreshAd();
        adView.setVisibility(View.GONE);

        //而(bconthread){
            adView.requestFreshAd();
            ShowAd();

            postDelayed();

            // HideAd();

            postDelayed();

        //}

        //调用这个删除与广告相关联的所有位图
        adView.cleanup();
        返回0;
    }
    私人无效HideAd()
    {
        //隐藏广告。
        adView.setVisibility(View.GONE);

        //淡入过一秒钟的4/10广告。
        AlphaAnimation动画=新AlphaAnimation(0.0,1.0F);
        animation.setDuration(400);
        animation.setFillAfter(真正的);
        animation.setInterpolator(新AccelerateInterpolator());
        adView.startAnimation(动画); // * /

    }
    私人无效ShowAd()
    {
        //取消隐藏广告。
        adView.setVisibility(View.VISIBLE);

        //淡入过一秒钟的4/10广告。
        AlphaAnimation动画=新AlphaAnimation(0.0,1.0F);
        animation.setDuration(400);
        animation.setFillAfter(真正的);
        animation.setInterpolator(新AccelerateInterpolator());
        adView.startAnimation(动画); // * /
    }
}
 

解决方案
  1. 您不必调用 AsyncTask.doInBackground ,此方法将通过AsyncTask的自身调用。
  2. AsyncTask.doInBackground 被称为在另一个线程,而不是UI线程,你可能不希望开始在它的动画,这将导致在UI的一些问题。
  3. 有很多方法可以使视图显示和消失的时间间隔,使用AsyncTask的是不是其中之一,我想。下面是示例code的使用处理程序来归档此。

 公共MyActivity延伸活动{

        私有静态最终诠释SHOW = 1;
        私有静态最终诠释隐藏= -1;

        私人查看AD浏览报;

        私人处理程序处理程序=新的处理程序(){
            公共无效的handleMessage(信息MSG){
                adView.setVisibility(msg.what);
            }
        }

        私人无效startTriggerThread(){
            新的Thread(){
                布尔秀= FALSE;
                公共无效的run(){
                    而(真){
                        如果(节目){
                            handler.sendEmptyMessage(View.GONE);
                        } 其他 {
                            handler.sendEmptyMessage(View.VISIBLE);
                        }
                        显示=秀!;
                        尝试 {
                            视频下载(区间);
                        }
                        赶上(InterruptException E){
                            // 忽略。
                        }
                    }
                }
            }。开始();
        }

        //其他方法
    }
 

I am new to programming in android. I have followed instruction and create a admob banner. How can I make it appear at certain intervals, and make it disappear if I want to? For example the admob banner can goes up and down at the bottom of the screen whenever it wants to. Thanks.

Edit:

I know that i can call adView.setVisibility( View.GONE ); to make the ads appear and disappear, but when i try to write it into a thread to make it appear and disappear with intervals, it just hangs there with a black screen.

Or is there anyway that admob can make their ad appear and disappear at intervals?

This is how i call the thread.

loadAdmob = new asyncAdmobProc();
loadAdmob.execute();
loadAdmob.doInBackground();//asyncAdmobProc();

The code:

//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 );//*/
    }
}

解决方案

  1. You don't have to call AsyncTask.doInBackground, this method will be called by AsyncTask itself.
  2. AsyncTask.doInBackground is called in other thread instead of UI thread, you may not want to start an animation in it, that will cause some problems on UI.
  3. There are lots of ways that you can make the view appear and disappear with intervals, using AsyncTask is not one of them, I think. Following is sample code which use Handler to archive this.

    public MyActivity extends Activity {

        private static final int SHOW = 1;
        private static final int HIDE = -1;

        private View adView;

        private Handler handler = new Handler() {
            public void handleMessage(Message msg) {
                adView.setVisibility(msg.what);                
            }
        }

        private void startTriggerThread() {
            new Thread() {
                boolean show = false;
                public void run() {
                    while (true) {
                        if (show) {
                            handler.sendEmptyMessage(View.GONE);
                        } else {
                            handler.sendEmptyMessage(View.VISIBLE);
                        }
                        show = !show;
                        try {
                            Thread.sleep(INTERVALS);
                        }
                        catch (InterruptException e) {
                            // Ignore.
                        }
                    }
                }
            }.start();
        }

        // Other methods
    }

这篇关于Admob的android系统中。如何使它出现和消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆