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添加为子视图


基础教程推荐
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01