Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android:如何初始化视图和画布?_Java_Android - Fatal编程技术网

Java Android:如何初始化视图和画布?

Java Android:如何初始化视图和画布?,java,android,Java,Android,我需要为我正在处理的项目初始化视图和画布,但经过一个小时左右的搜索后,我无法确定它们等于什么 以下是我目前掌握的代码: public class DisplayMap extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { dis

我需要为我正在处理的项目初始化视图和画布,但经过一个小时左右的搜索后,我无法确定它们等于什么

以下是我目前掌握的代码:

 public class DisplayMap extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        try {
            displayMap();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (SlickException e) {
            e.printStackTrace();
        }

    }

    public void displayMap() throws IOException, SlickException {
        loadWorld("assets/World.tmx");
    }

    public void loadWorld(String path) throws IOException {
        View view = ?????;
        Canvas canvas = ?????;

        //World loading goes here
    }
    }

那么,有谁能建议我如何初始化视图和画布吗?还是我的做法完全错了?

您需要编写一个加载地图的自定义视图,然后在活动中使用该自定义视图

TMXView.java
中:

public class TMXView extends View {
  public TMXView(Context context) {
    super(context);
    // Load map
  }

  public void onDraw(Canvas canvas) {
     // Draw the map on the canvas
  }
}
在活动的
onCreate
中:

 View view = new TMXView(this);
 setContentView(view);

有关更多信息,请参阅我关于自定义组件的演讲:

您有TMX映射的解析器吗?没有,我找不到可用的解析器/无法找到它们。因此,我正在制作自己的解析器,并根据我的一个C#项目对其进行建模;setContentView(视图);非常感谢。但是现在,我如何初始化属性集?非常感谢!你能看看我的另一个问题吗?我们很难弄清楚。