最后,我的GLSurfaceview顶部有一个横幅广告。但是,它显示为黑色背景,占据了整个屏幕的宽度,并像这样覆盖了我的游戏区域的顶部(我还应该指出,游戏区域也向下移动了一点,所以底部也不见了) .
我需要做的是将横幅移动到屏幕底部,并将其保持在中央并删除此黑色背景,使其看起来像这样:
我尝试使用 XML,但遇到了很多错误,所以我改用 Java 完全执行此操作(并设法做到这一点) - 但是关于如何使用 GLSurfaceView 执行此操作的质量信息缺乏恕我直言,所以我希望有人可以告诉我哪里出错了。
代码
这是我的 onCreate() 方法:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create an ad.
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);
// Add the AdView to the view hierarchy. The view will have no size
// until the ad is loaded.
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
// Create an ad request.
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(TestDeviceID)
.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
//Request full screen
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
//Create a displayMetrics object to get pixel width and height
metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
width = metrics.widthPixels;
height = metrics.heightPixels;
//Create and set GL view (OpenGL View)
myView = new MyGLSurfaceView(MainActivity.this);
layout.addView(adView);
layout.addView(myView);
//Create a copy of the Bundle
if (savedInstanceState != null){
newBundle = new Bundle(savedInstanceState);
}
//Set main renderer
setContentView(layout);
}
当横幅更改时,它也会出现“闪烁”,但我可以在单独的问题中处理。