我想使用原生的sdk界面布局(普通应用程序如何)设计我的游戏菜单,并将其链接到BaseGameActivity或GameScene,我知道如何使用sdk native设计界面,但我不知道如何在andengine上实现它:S
我无法找到任何解决方案,我希望任何人都可以帮助我找到最好的方法或使用它们的方法。
抱歉我的英语不好。
更多信息:我知道如何在我的baseactivity上添加一点framelayout,但我可以使用一组菜单(2/3)并且你可以移动它,然后进入游戏并退出游戏:)
对不起我的英语
答案 0 :(得分:3)
嗯,我这样做有效:)
仅使用布局等创建普通活动..并使用intent.putExtra();将特定信息发送到BaseGameActivy,然后,在onCreateResources()上设置一系列条件以确定我之前按下,并设置所希望的场景。
对不起我的英文:)
答案 1 :(得分:2)
编辑:从原始网站导入的教程
注意:如果您在这些布局中更改宽度和高度,可能会出现填充错误,因此请小心(此解决方案适用于全屏使用)
在项目的目录 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>
您只需在班级中指定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;
}
}
警告:根节点必须是合并节点!在这里你可以做你想做的事。
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视图。
注意:当您切换到WYSIWIG编辑器时会编译UI Java代码,因此如果您不添加下面的链接代码,您将无法在使用它的活动中看到布局的内容。
自定义布局: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" />