Android - admob和SurfaceView问题

时间:2012-07-27 16:10:02

标签: android admob surfaceview

我正在尝试开始使用admob,但它似乎比我想象的更难。 我只是想写一个小测试应用程序,我会在表面视图上绘制一些内容并添加一个admob示例。

在我的主要活动中,我在onCreate方法中执行以下操作:

AndroidFastRenderView是我对SurfaceView的实现。

requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;

        int frameBufferWidth = isLandscape ? 480 : 320;
        int frameBufferHeight = isLandscape ? 270 : 430;

        Bitmap frameBuffer = Bitmap.createBitmap(frameBufferWidth,
                frameBufferHeight, Config.RGB_565);


        renderView = new AndroidFastRenderView(this, frameBuffer);
        graphics = new AndroidGraphics(getAssets(), frameBuffer);

        adView = new AdView(this, AdSize.BANNER, "XXX");
        adView.setVisibility(View.VISIBLE);


        FrameLayout layout = new FrameLayout(this);
        FrameLayout.LayoutParams gameParams = new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT,
                FrameLayout.LayoutParams.WRAP_CONTENT);

        FrameLayout.LayoutParams adsParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                FrameLayout.LayoutParams.WRAP_CONTENT);

        layout.addView(adView, 0, adsParams);

        layout.addView(renderView, 1, gameParams);
        setContentView(layout);


        AdRequest adRequest = new AdRequest();
        adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
        adView.loadAd(adRequest);

当我这样做时,整个屏幕都充满了AndroidFastRenderView。 但是,当我不添加AndroidFastRenderView时,广告就会出现。 所以我认为问题在于,AndroidFastRenderView可能是在我的广告上面绘制的(也许我的框架缓冲区大小有问题)或者AndroidFastRenderView“窃取”了广告的空间。

我希望你明白我的问题是什么,任何人都可以帮我解决问题

你的,卢卡斯

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用RelativeLayout而不是FrameLayout?

final int adId = 0x12345;
adView.setId(adId);
RelativeLayout layout = new RelativeLayout(this);

RelativeLayout.LayoutParams adParams =
    new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                                    RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
RelativeLayout.LayoutParams gameParams =
    new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                                    RelativeLayout.LayoutParams.WRAP_CONTENT);
gameParams.addRule(RelativeLayout.BELOW, adId);
layout.addView(adView, adParams);
layout.addView(renderView, gameParams);
setContentView(layout);