我可以在 libgdx GL 表面上覆盖 Android 视图吗? [英] Can I have Android Views overlayed on top of the libgdx GL surface?

查看:11
本文介绍了我可以在 libgdx GL 表面上覆盖 Android 视图吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 libgdx 的 OpenGL Surface 中发生的所有事情之上显示一些自定义视图(例如带有阿拉伯/亚洲文本的 TextViews)(<--我假设它是一个表面视图).这可能吗?怎么样?

I would like to display some custom views ( e.g. TextViews with Arabic/Asian text) on top of everything that happens in libgdx's OpenGL Surface (<--I assume it's a surface view). Is this possible? How?

动机是我有一个经过验证的组件可以在我现有的代码中显示文本,我想继续使用它.

The motivation is that I have a proven component for displaying text in my existing code and I would like to keep using this.

我之前使用过其他带有视图层次结构的 GLSurfaceView.只是想知道如何/是否可以在 libgdx 中完成.性能并不重要,因为 libgdx 中的游戏"是一个简单的益智游戏,当显示文本视图时,游戏几乎暂停了.

I have used other GLSurfaceViews with View hierarchies before. Just wondering how/if this can be done in libgdx. Performance doesn't matter all to much because the "game" in libgdx is a simple puzzle game, and when the text views are shown, the game is pretty much paused.

推荐答案

可以!这份关于在 Libgdx 中使用 Admob 的官方指南可以帮助您显示自定义视图.尽管它专注于集成 Admob 广告,但您可以使用该机制在 OpenGL Surface 之上创建和显示视图.例如,这是您在 android 游戏的表面视图顶部显示文本视图的方式:

Yes you can! This official guide on using Admob in Libgdx has all you need help you display custom views. Though it focuses on integrating Admob ads, you can use the mechanism to create and display views on top of the OpenGL Surface. For example this is how you'd display a text view on top of your android game's surface view:

   @Override public 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 HelloWorld(this), false);

        // Create and setup the TextView
        TextView helloText = new TextView(this); 

        // Add the libgdx view
        layout.addView(gameView);

        // Add the TextView
        RelativeLayout.LayoutParams textViewParams = 
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
                    RelativeLayout.LayoutParams.WRAP_CONTENT);
        textViewParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        textViewParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

        layout.addView(helloText, textViewParams);

        // Hook it all up
        setContentView(layout);
    }

这篇关于我可以在 libgdx GL 表面上覆盖 Android 视图吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆