Can I have Android Views overlayed on top of the libgdx GL surface?(我可以在 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 视图吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我可以在 libgdx GL 表面上覆盖 Android 视图吗?
基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01