0

我想创建一个在其他 GUI 元素中具有 3D 输出的应用程序,尤其是任务栏。在我让示例使用 RajawaliActivity(教程 1)工作后,我没有使用 RajawaliFragment 做同样的事情。

不幸的是,我找不到使用 RajawaliFragment 和稳定版本 0.9 的示例,还有更多内容吗?

我的拉贾瓦利片段:

public class MyFragment extends RajawaliFragment {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        MyRenderer renderer = new MyRenderer(getActivity());
        renderer.setSurfaceView(mSurfaceView);

        super.setRenderer(renderer);
    }
}

渲染器(名称除外)是示例代码的副本,并且可以与 RajawaliActivity 一起正常工作。此外,片段确实被附加,但没有调用任何渲染器方法(当然构造函数除外)。

4

2 回答 2

0

我能够使用来自RajawaliExamples项目的示例片段之一来工作。

我采取的步骤是:

  1. 在我的 MainActivity 中,我扩展了 ActionBarActivity 并在我的 onCreate() 中,我能够将片段添加到我的容器中:

    public class MainActivity extends ActionBarActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (savedInstanceState == null) {
    
        ObjectPickingFragment testFragment = new ObjectPickingFragment();
        getFragmentManager().beginTransaction()
            .add(R.id.container, testFragment, "testFragment")
            .commit();
    }
    }
    
  2. 我的 ObjectPickingFragment 只是示例中的一个示例片段。它继承自 AExampleFragment 但这只是我正在使用示例项目的 b/c。在我的实际代码中,我只有我真正的片段。

整个示例应用程序使用 Fragments,因此应该会给您一些很好的示例。确保您的 MyRenderer 扩展了 RajawaliRenderer。

于 2015-02-04T07:27:39.910 回答
0

我错过的是 onCreateView 方法。我以为这只是我不需要的加载屏幕,所以我省略了它,但我真正需要做的是:

public class MyFragment extends RajawaliFragment {
    public void onCreate(Bundle savedInstanceState) {
        // this part was fine
    }

    public View onCreateView(LayoutInflater i, ViewGroup c, Bundle b) {
        return mSurfaceView;
    }
}
于 2015-02-14T17:42:22.380 回答