【问题标题】:Android - Andengine - How to use native UI SKDAndroid - Andengine - 如何使用原生 UI SKD
【发布时间】:2012-10-16 22:27:38
【问题描述】:

我想用原生sdk界面布局,(How a normal app)来设计我的游戏菜单,并链接到BaseGameActivity,或者GameScene,我知道如何使用sdk native设计界面,但我不知道如何在andengine上实现它:S

我找不到任何解决方案,我希望任何人都可以帮助我找到最好的方法,或者使用这些方法的方法。

对不起,我的英语不好。


更多信息:我知道如何在我的基本活动中添加一个小框架布局,但我可以设置一组菜单 (2/3),你可以在上面移动,然后进入游戏并退出游戏 :)

再次对不起我的英语

【问题讨论】:

    标签: android user-interface sdk native andengine


    【解决方案1】:

    好吧,我这样做很有效:)

    只创建一个普通的活动,带有布局等。并使用intent.putExtra();将特定信息发送到 BaseGameActivy,然后,在 onCreateResources() 上,我设置了一系列条件来确定我之前按下的,并设置所需的场景。

    对不起我的英语:)

    【讨论】:

      【解决方案2】:

      编辑:从原网站导入教程

      如何在 AndEndine 中使用 UI Android SDK

      注意:如果您在这些布局中更改宽度和高度,可能会出现填充错误,因此请小心(此解决方案适用于全屏使用)

      XML 布局

      在您的项目目录res/layout中创建一个名为themainactivity.xml的空文件,并在其中放入以下内容。

      注意:将属性tools:context 设置为您的应用程序活动名称,以点开头(此处:.MyMainActivity)

      XML 布局文件:res/layout/themainactivity.xml

      <RelativeLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content">
          <!-- code placed here will be above the AndEngine render -->
      </RelativeLayout>
      

      Java 类

      你只需要在你的类中指定 ID。

      MyMainActivity.java

      package com.example;
      
      import org.andengine.ui.activity.SimpleLayoutGameActivity;
      
      public class MyMainActivity extends SimpleLayoutGameActivity  
      {
          @Override
          protected int getLayoutID()
          {
              return R.layout.themainactivity;
          }
      
          @Override
          protected int getRenderSurfaceViewID()
          {
              return R.id.gameSurfaceView;
          }
      }
      

      在 AndEngine 中创建自定义 Android SDK 布局

      XML 布局

      警告:根节点必须是合并节点!在里面你可以做你想做的事。

      XML 布局文件:res/layout/my_view.xml

      <?xml version="1.0" encoding="utf-8"?>
      <merge xmlns:android="http://schemas.android.com/apk/res/android">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >
            <Button
                android:id="@+id/button1"
                android:layout_width="fill_parent"
                android:layout_height="40dp"
                android:text="Dat button" />
        </LinearLayout>
      </merge> 
      

      控制器类

      为了能够使用您的界面,您必须使用 inflater 服务将其链接到 XML 视图。

      注意:UI Java 代码是在您切换到 WYSIWIG 编辑器时编译的,因此如果您不添加下面的链接代码,您将不会在使用它的活动中看到布局的内容。

      自定义布局:MyView.java

      package com.example;
      
      import android.content.Context;
      import android.util.AttributeSet;
      import android.view.LayoutInflater;
      import android.widget.LinearLayout;
      
      public class MyView extends LinearLayout 
      {
          public MyView(Context context, AttributeSet attrs)
          {
              super(context, attrs);
      
              // Link to the XML view
              LayoutInflater.from(context).inflate(R.layout.my_view, this, true);
      
              // Link to the XML view (alternative using service, you can delete if you don't need it)
              //LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              //inflater.inflate(R.layout.my_view, this);
          }
      }
      

      在其他活动中重复使用

      只需在活动布局中添加此代码即可。

      <com.example.MyView
          android:id="@+id/myView1"
          android:layout_width="100dp"
          android:layout_height="wrap_content" />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-04-14
        • 2013-06-30
        • 1970-01-01
        • 1970-01-01
        • 2012-09-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多