【发布时间】:2014-08-04 16:36:59
【问题描述】:
我正在尝试在我的简单游戏中添加广告。我已按照此处的说明进行操作:[url]https://github.com/libgdx/libgdx/wiki/Admob-in-libgdx[/url]。 我的 AndroidLauncher 看起来像这样:
包 com.redHoodie.android;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.google.ads.AdSize;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.redHoodie.MainHoodie;
public class AndroidLauncher extends AndroidApplication {
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create the layout
RelativeLayout layout = new RelativeLayout(this);
// Do the stuff that initialize() would do for you
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// Create the libgdx View
View gameView = initializeForView(new MainHoodie());
// Create and setup the AdMob view
AdView adView = new AdView(this, AdSize.BANNER, "xxxxx"); // Put in your secret key here
adView.loadAd(new AdRequest());
// Add the libgdx view
layout.addView(gameView);
// Add the AdMob view
RelativeLayout.LayoutParams adParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
adParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
layout.addView(adView, adParams);
// Hook it all up
setContentView(layout);
}
}
这三行代码用eclipse加下划线:
View gameView = initializeForView(new MainHoodie(),false);
// Create and setup the AdMob view
AdView adView = new AdView(this, AdSize.BANNER, "xxxxx"); // Put in your secret key here
adView.loadAd(new AdRequest());
ecllipse 告诉我删除这些方法的所有参数,但是当我这样做时,我的游戏在发布后就迷恋了。我正在使用 libgdx 1.2
【问题讨论】:
-
你是否将 Admob 添加到 gradle 依赖项中?