Java 如何在不使用xml的情况下向游戏中添加广告?
我想在我的游戏中添加广告,但我不使用xml。我知道我应该学习,但是,这是我的第一个游戏,我只是想先发布它。这就是我目前所拥有的。我也一直跟踪到说编辑main_activity.xml的部分。我现在应该如何添加广告Java 如何在不使用xml的情况下向游戏中添加广告?,java,android,xml,android-activity,admob,Java,Android,Xml,Android Activity,Admob,我想在我的游戏中添加广告,但我不使用xml。我知道我应该学习,但是,这是我的第一个游戏,我只是想先发布它。这就是我目前所拥有的。我也一直跟踪到说编辑main_activity.xml的部分。我现在应该如何添加广告 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //fullscreen requestWindowFeatur
@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();
}
此代码替代了在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);
以下代码的其余部分请参见教程