使用 ViewGroup.addView() 将 GestureOverlayView 添加到 SurfaceView 游戏面板

发布于 2024-09-13 13:50:41 字数 1555 浏览 1 评论 0原文

经过这里好心人的大力帮助,我终于几乎让我的小游戏面板(这是一个 SurfaceView 类)启动并使用 GestureOverlayView 运行。通过使用 addView,我终于能够添加 GestureOverlayView 并使其正常工作,问题是调用此方法:

    /** create the login form */
private ViewGroup _createGameStuffs() {
  GestureOverlayView gestures = new GestureOverlayView(this);       
  gestures.setOrientation(gestures.ORIENTATION_VERTICAL);
  gestures.setEventsInterceptionEnabled(true);
  gestures.setGestureStrokeType(gestures.GESTURE_STROKE_TYPE_MULTIPLE);

  gestures.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
          LayoutParams.FILL_PARENT));

  //GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
  gestures.addOnGesturePerformedListener(this);
  Panel p = new Panel(this); //my game view
  panel.addView(p,0);       //add it to the group
  panel.addView(gestures,1); //add the gestureoverlayview i made to the group

  return panel;
}

    public void onCreate(Bundle savedInstanceState) {
               super.onCreate(savedInstanceState);
               requestWindowFeature(Window.FEATURE_NO_TITLE);
               mLibrary = GestureLibraries.fromRawResource(this, R.raw.myspells);

                 // create the panel to enclose everything
               View mainPanel = _createGameStuffs();

              // show the panel on the screen
              setContentView(mainPanel);
              //setContentView(p);
 }

根据我给出的索引,哪个视图占据主导地位。这让我相信我的游戏面板必须作为子视图添加到 GestureOverlayView,这是正确的吗?如果是这样,我如何获取 GestureOverlayView 的子视图?或者是相反,GestureOverlayView 成为我的主视图的子视图?

After much help from the good people here, I finally almost got my little game panel (thats a surfaceview class) up and running with a GestureOverlayView. Through the use of addView I finally was able to add the GestureOverlayView and get it to work, the trouble is that calling this:

    /** create the login form */
private ViewGroup _createGameStuffs() {
  GestureOverlayView gestures = new GestureOverlayView(this);       
  gestures.setOrientation(gestures.ORIENTATION_VERTICAL);
  gestures.setEventsInterceptionEnabled(true);
  gestures.setGestureStrokeType(gestures.GESTURE_STROKE_TYPE_MULTIPLE);

  gestures.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
          LayoutParams.FILL_PARENT));

  //GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
  gestures.addOnGesturePerformedListener(this);
  Panel p = new Panel(this); //my game view
  panel.addView(p,0);       //add it to the group
  panel.addView(gestures,1); //add the gestureoverlayview i made to the group

  return panel;
}

    public void onCreate(Bundle savedInstanceState) {
               super.onCreate(savedInstanceState);
               requestWindowFeature(Window.FEATURE_NO_TITLE);
               mLibrary = GestureLibraries.fromRawResource(this, R.raw.myspells);

                 // create the panel to enclose everything
               View mainPanel = _createGameStuffs();

              // show the panel on the screen
              setContentView(mainPanel);
              //setContentView(p);
 }

Depending upon which index I give which view takes presedence. This leads me to believe my game panel has to be added as a child view to the GestureOverlayView, is this correct? If so, how do I get at the children views of the GestureOverlayView? Or is it the other way around, GestureOverlayView becomes a child of my main view?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文