我有一个问题,设置调整我的看法编程到屏幕的底部。基本上,我只想把我的AdMob的广告在屏幕底部。我不能用XML做,因为这会更麻烦。现在我已经得到了广告工作,并手动将其添加到 RelativeLayout的
,但默认情况下它会出现在屏幕的顶部。我试图用重力命令,但不能得到它的工作。
I got a problem with setting aligning my view programatically to the bottom of the screen. Basically I just want to place my admob advert at the screen bottom. I can't do it with XML because it would be even more troublesome. Right now I already got the advert working, and added it manually to the RelativeLayout
, but by default it appears at the top of the screen. I tried to use the gravity command, but couldn't get it working.
这里的code片断:
_glSurfaceView = new CCGLSurfaceView(this);
adView = new AdView(this, AdSize.BANNER, "a14e04559caea39");
adView.loadAd(new AdRequest());
adView.setGravity(Gravity.BOTTOM);
RelativeLayout rl = new RelativeLayout(this);
rl.addView(_glSurfaceView);
rl.addView(adView);
setContentView(rl);
adView.loadAd(new AdRequest());
谁能帮我?
蜻蜓的回答为我工作。 下面是完整的code段为参照
dragonfly's answer worked for me. Here is the complete code snippet for the reference
adView = new AdView(this, AdSize.BANNER, "xxxxxxxxxxxxxxx");
panel = new MySurfaceView(this);
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
RelativeLayout rl = new RelativeLayout(this);
RelativeLayout.LayoutParams lay = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
lay.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
rl.addView(panel);
rl.addView(adView, lay);
setContentView(rl);
adView.loadAd(adRequest);