5

Disclaimer: this is a strange issue that only happens in a Kindle Fire (so far).

Technologies Involved: Android SDK, Eclipse, LibGDX.

I have a relatively simple app running with LibGDX. The way LibGDX works is by having an OpenGL thread that will call Create() (once) and then Render() as many times as possible (so you can do your render…).

So when you initialize the Device, your "Create()" method is called and then when the OpenGL surface is initialized (all this happens automagically), your Render() starts getting called.

If the OpenGL context is lost, destroyed, etc. your Resize(width,height) method is called by LibGDX.

So far. So good.

Now I came across a strange issue with a Kindle Fire where things looked a few pixels off or "cut". The Kindle Fire has a "softbar" at the bottom of the screen (20 pixels) that you can't hide or skip, which is "kind of ok" because the device doesn't have physical buttons. You're expected to touch this soft bar and get a bigger bar to go back, go home, etc. According to Amazon, this bar cannot be removed. (is not 100% clear but nobody has found a way -that is not breaking the Amazon rules). The only App I've seen that removes that is the Amazon Video Players for videos streamed from Amazon's Cloud only. So as you can see, there doesn't seem to be a way to "permanently" hide that bar.

So if the bar is there, your real screen state is not the hardware resolution 1024x600 (landscape) but 1024x580. So I added some logging to my methods to see what was going on, and was surprised with this… (remember the create(), render() and resize() methods):

12-23 15:17:04.119: I/myapp(19921): SCREEN HEIGHT AT CREATE(): 600
[snip other unrelated log stuff]
12-23 15:17:04.673: I/myapp(19921): SCREEN HEIGHT AT RENDER() LOOP: 600
[snip other unrelated log stuff]
12-23 15:17:04.705: I/myapp(19921): MyApp - Resize() Called.
12-23 15:17:04.705: I/myapp(19921): SCREEN HEIGHT AT RENDER() LOOP: 580

So the screen has been "resized" by the Kindle Fire, "at some point".

Has anyone come across something like this?

This is a screenshot (notice the black bar on top, that's not added by me!). Forgive me for blurring the image but this is a client's project and I can't "disclose" anything.

enter image description here

The fun part begins when sometimes, the bar won't be there and the app will look like the next (again, sry for the blur). Notice how the top bar is not there…</p>

enter image description here

Upon a closer examination of both shots, you can tell that the bottom (which should be the same), is not. The kindle is doing strange things.

Any ideas?

The assets were originally packed as 1024x600 but we have changed that (580 now) and will assume that the viewport is now 1024x580 but I was wondering if anyone found a better way to deal with this nonsense? :)

note: we do have android:theme="@android:style/Theme.NoTitleBar.Fullscreen" in the manifest. Doesn't do anything.

Thanks in advance.

4

3 回答 3

6

Kindle fire 有一个奇怪的行为,一旦应用程序加载似乎它“移动”屏幕向上 20 像素(软栏高度),因此您的应用程序看起来有几个像素关闭或剪切。这是因为当您创建GLSurfaceView并设置渲染器时,它会两次调用onSurfaceChanged方法。

第一次调用 onSurfaceCreated 后,分辨率值为 1024x600,第二次调用 onDrawFrame 后,分辨率值为 1024x580。

解决方案,您必须控制对 onSurfaceChanged 的​​两个调用并调整 opengl 视口的大小。

    private static boolean appStarted = false;
    ...

    private static class Renderer implements GLSurfaceView.Renderer 
    {
        public void onSurfaceChanged(GL10 gl, int width, int height) 
        {
            if ( !appStarted )
            {
                 //Initialization (Resolution 1024x600)
            }
            else
            {
                 //Second call, screen resolution changed (Resolution 1024x580)
                 //Resize(width,height)
            }   
            appStarted = true;
        }

        public void onDrawFrame(GL10 gl) {
        //Render()
        }

        public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        //Create()
        }
    }
于 2012-02-10T09:03:11.170 回答
1

尝试使用这个:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

来源:https ://developer.amazon.com/help/faq.html?ref_=pe_132830_21362890#KindleFire

于 2012-02-03T00:29:47.057 回答
0

我最近遇到了这个问题,想知道您是否已经找到了解决方案。

黑条出现是因为您的应用报告高度为 580 像素高。OpenGL 有一个坐标系,其中 (0,0) 位于屏幕的左下角。

出于某种原因,Kindle 的软栏没有将 EGLSurface 向上移动 20 个像素。但是,调整大小会将大小减小 20 像素,留下黑条。所以问题是 EGLSurface 的位置。有时,由于时间的关系,似乎在调整大小后会发生重定位(使黑条消失)。

于 2012-07-11T09:01:38.237 回答