This is my title screen with just a button (main.xml)
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/start" android:text="start"></Button>
- </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
This is the layout I use for the game, where com.switcher.TestSurface is a SurfaceView (surface.xml)
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <com.switcher.TestSurface xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/testsurface"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"/>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
This is my Activity
Using java Syntax Highlighting
- package com.switcher;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- public class SwitcherActivity extends Activity {
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Button btnStart = (Button)findViewById(R.id.start);
- btnStart.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- setContentView(R.layout.surface);
- }
- });
- }
- }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
and this is my SurfaceView
Using java Syntax Highlighting
- package com.switcher;
- import android.content.Context;
- import android.graphics.Canvas;
- import android.util.AttributeSet;
- import android.view.SurfaceHolder;
- import android.view.SurfaceView;
- public class TestSurface extends SurfaceView implements SurfaceHolder.Callback {
- private SurfaceHolder mSurfaceHolder;
- public TestSurface(Context context, AttributeSet attrs) {
- super(context, attrs);
- mSurfaceHolder = getHolder();
- mSurfaceHolder.addCallback(this);
- setFocusable(true);
- }
- private void doDraw(Canvas canvas) {
- canvas.drawARGB(255, 255, 255, 0);
- }
- public void surfaceCreated(SurfaceHolder holder) {
- Canvas c = null;
- try {
- c = mSurfaceHolder.lockCanvas(null);
- synchronized (mSurfaceHolder) {
- doDraw(c);
- }
- } finally {
- if (c != null) {
- mSurfaceHolder.unlockCanvasAndPost(c);
- }
- }
- }
- public void surfaceDestroyed(SurfaceHolder holder) {}
- public void surfaceChanged(SurfaceHolder holder, int format, int width,
- int height) {}
- }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
What is the problem?



