質問

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.

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.

役に立ちましたか?

解決

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);
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top