我想在我的游戏中添加广告,但我不使用xml。我知道我应该学习,这是我的第一场比赛,我只是想先发布它。这就是我到目前为止所拥有的。我也跟着Admob tutorial一直到编辑main_activity.xml的部分。我该如何开始添加广告?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//fullscreen
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.Flag_FULLSCREEN);
//scale image
Display display = getWindowManager().getDefaultDisplay();
size = new Point();
dispay.getSize(size);
dispX = size.x;
dispY = size.y;
bg = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(
getResources(), R.drawable.bg),dispX,dispY,true);
bg = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(
getResources(), R.drawable.losescreen),GamePanel.rescaleX(805),GamePanelrescaleY(1105),true);
bg = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(
getResources(), R.drawable.playbutton),GamePanel.rescaleX(242),GamePanelrescaleY(242),true);
setContentView(new GamePanel(this));
contextOfApplication = getApplicationContext();
}
答案 0 :(得分:0)
此代码可替代在xml中添加adview:
AdView adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);
// Lookup the layout where you want to place the ad unit
// give the layout an id in the layout xml
LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);
// Add the adView to the activity's layout
layout.addView(adView);
根据教程,下面的其余代码。