如何添加libgdx作为一个子视图的android [英] How to add libgdx as a sub view in android

查看:233
本文介绍了如何添加libgdx作为一个子视图的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的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类,而不是查看。

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)方法,将返回查看您可以添加到您的布局。

The AndroidApplication class (which extends activity) has a method named initializeForView(ApplicationListener, AndroidApplicationConfiguration) that will return a View you can add to your layout.

所以,你的测试类可以扩展,而不是活动AndroidApplication这样就可以调用这个方法并查看添加到您的布局。

So your Test-class can extend AndroidApplication instead of Activity so that you can call that method and add the View to your layout.

如果这不是一个选项,因为某些原因,看看是什么<一个href="https://github.com/libgdx/libgdx/blob/master/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidApplication.java#L223"相对=nofollow> AndroidApplication源$ C ​​$ C 做,并模仿。

If that's not an option, for some reason, take a look at what AndroidApplication source code does, and mimic that.

这篇关于如何添加libgdx作为一个子视图的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆