如何在视图中添加横幅?

时间:2013-04-10 10:18:00

标签: android android-layout

首先,我在MainActivity.java中有一些观点如下:

CanvasMainMenu canvasMenu = new CanvasMainMenu(this);
setContentView(canvasMenu);

类CanvasMainMenu扩展View,我想在此视图中添加一些横幅。

如何在我的CanvasMainMenu中添加横幅广告?

1 个答案:

答案 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);
}