简体   繁体   中英

Surfaceview with admob

Im trying to create a game. Im using a Surfaceview to draw on, and now I would like an admob view to show up at the buttom of the screen. I have tried to create a RelativeLayout programtically, but currently the only view to be shown is the surfaceview , the admob view is not shown!

This is the code:

RelativeLayout layout = new RelativeLayout(this);

    AdView admobView = new AdView(this, AdSize.BANNER, "MY_ADMOB_ID");
    RelativeLayout.LayoutParams admobParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT);

    admobParams.addRule(RelativeLayout.ALIGN_BOTTOM);

    admobView.setLayoutParams(admobParams);

    layout.addView(admobView);

    RelativeLayout.LayoutParams threadParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT);
    threadParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);

    admobView.loadAd(new AdRequest());

    TimermodeThread timerThread = new TimermodeThread(getApplicationContext());
    timerThread.setLayoutParams(threadParams);
    layout.addView(timerThread);

    setContentView(layout);

Is there anyone who could help me?

Thanks!

EDIT

I can see in Log that I have recieved the ad. So, im guessing the surfaceview is taking all the space!

I guess your surface view is taking up the whole screen. instead of using the relative layout use Framelayout. and add the code for layouting the ad at the end.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM