How to add libgdx as a sub view in android(如何在android中将libgdx添加为子视图)
问题描述
我的 main.xml 如下:
I have main.xml as follows:
<RelativeLayout>
...
<FrameLayout
android:id="@+id/panel_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.libgdx.Sheet3DViewGdx
android:id="@+id/m3D"
android:layout_width="1000dp"
android:layout_height="600dp"
/>
</FrameLayout>
...
</RelativeLayout>
而我的主要活动类如下:
And my main activity class is as follows:
public class Test extends Activity {
MainActivity m3DActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
我的 GDX 类如下,它扩展了 ApplicationListener 类而不是 View.
My GDX class is as follows which extend ApplicationListener class rather than View.
public class Sheet3DViewGdx implements ApplicationListener{
@Override
public void create() {
InputStream in = Gdx.files.internal("data/obj/Human3DModel.obj").read();
model = ObjLoader.loadObj(in);
}
@Override
public void dispose() {
}
@Override
public void pause() {
}
@Override
public void render() {
Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
model.render(GL10.GL_TRIANGLES);
}
@Override
public void resize(int arg0, int arg1) {
float aspectRatio = (float) arg0 / (float) arg1;
}
@Override
public void resume() {
}
}
现在,我应该如何在主布局中添加 Sheet3DViewGdx 作为子视图?
Now, how should I add Sheet3DViewGdx as a subview in my main layout?
推荐答案
AndroidApplication 类(它扩展了活动)有一个名为 initializeForView(ApplicationListener, AndroidApplicationConfiguration)
的方法,该方法将返回一个 View
你可以添加到你的布局中.
The AndroidApplication class (which extends activity) has a method named initializeForView(ApplicationListener, AndroidApplicationConfiguration)
that will return a View
you can add to your layout.
因此,您的 Test-class 可以扩展 AndroidApplication 而不是 Activity,以便您可以调用该方法并将 View 添加到您的布局中.
So your Test-class can extend AndroidApplication instead of Activity so that you can call that method and add the View to your layout.
如果由于某种原因这不是一个选项,请查看 AndroidApplication 源代码可以,并模仿它.
If that's not an option, for some reason, take a look at what AndroidApplication source code does, and mimic that.
这篇关于如何在android中将libgdx添加为子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在android中将libgdx添加为子视图
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01