我一直试图在Libgdx上为我的游戏添加一个横幅,我已经阅读了一些文档并最终编写了这段代码:
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
//initialize(new GameMain(), config);
RelativeLayout layout = new RelativeLayout(this);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
View gameView = initializeForView(new GameMain(), config);
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("pub-xxxxxxxxxxx");
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
layout.addView(gameView);
RelativeLayout.LayoutParams adParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
layout.addView(adView, adParams);
setContentView(layout);
}
}
问题是它没有显示广告,我无法弄清楚原因。 (问题不在于发布商ID我刚刚将其改为将其放在此处,在代码中它是我真正的发布商ID)
不能有人发现问题吗?
答案 0 :(得分:0)
您似乎缺少导入的Android支持库。
答案 1 :(得分:0)
也许这有助于https://github.com/libgdx/libgdx/wiki/Google-Play-Game-Services-in-LibGDX
看看bulild.gradle:
project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
compile project(":core")
compile project(":libraries:BaseGameUtils")
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
compile 'com.android.support:appcompat-v7:20.0.+'
compile 'com.android.support:support-v4:20.0.+'
compile 'com.google.android.gms:play-services:5.0+'
}
}