我可以將Android視圖覆蓋在libgdx GL表面之上嗎?

[英]Can I have Android Views overlayed on top of the libgdx GL surface?


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?

我想在libgdx的OpenGL Surface中發生的所有事情上顯示一些自定義視圖(例如帶有阿拉伯語/亞洲文本的TextViews)(< - 我認為它是一個表面視圖)。這可能嗎?怎么樣?

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

我的動機是我在現有代碼中顯示文本的成熟組件,我想繼續使用它。

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.

我之前使用過其他GLSurfaceViews和View層次結構。只是想知道如何在libgdx中完成這項工作。性能並不重要,因為libgdx中的“游戲”是一個簡單的益智游戲,當顯示文本視圖時,游戲幾乎暫停了。

1 个解决方案

#1


8  

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:

是的你可以!這篇關於在Libgdx中使用Admob的官方指南,您需要幫助您顯示自定義視圖。雖然它專注於集成Admob廣告,但您可以使用該機制在OpenGL Surface上創建和顯示視圖。例如,這就是你如何在Android游戲的表面視圖上顯示文本視圖:

   @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);
    }

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2014/05/15/72a32fa26c2daf3a696ed2c918a209c1.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com