首先,我在MainActivity.java
中有一些观点如下:
CanvasMainMenu canvasMenu = new CanvasMainMenu(this);
setContentView(canvasMenu);
类CanvasMainMenu扩展View
,我想在此视图中添加一些横幅。
如何在我的CanvasMainMenu
中添加横幅广告?
答案 0 :(得分:0)
这有用吗?
private static FrameLayout mFrameLayout = null;
private static MainView mMainView = null;
private static AdView mAdView = null;
//.....
protected void onCreate(Bundle icicle) {
//.....
AdView = new AdView(this, AdSize.BANNER, "a14d3678cfc9fb7");
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
mFrameLayout = new FrameLayout(getApplicationContext());
mMainView = new MainView(getApplicationContext());
mAdView.loadAd(adRequest);
mAdView.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL);
//.....
mFrameLayout.addView(mAdView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
}
public void setOverlayView(int gameMode) {
mAdView.setVisibility(View.VISIBLE);
}