Hi, I have been wondering this problem for a long time, and can't find
out the answer.
In LunarLander, the code for presenting the surface is
setContentView(R.layout.lunar_layout);
with it's XML below:
<FrameLayout ...>
<com.example.android.lunarlander.LunarView
android:id="@+id/lunar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<RelativeLayout...>
</RelativeLayout>
I've tried many times, and viewed many other's code.
They often use
setContentView(new LunarView(this));
I can work with this code.
But I can't work with
setContentView(R.layout.lunar_layout);
It come up with some forcing close error.
Please help me. I've searched stackoverflow, but android discussion is
not to many.
http://www.droidnova.com/playing-with-graphics-in-android-part-ii,160.html
http://android-er.blogspot.com/2010/05/android-surfaceview.html
The sites that I've read
This is my code :
[gogogo.java]
package my.darling;
import android.app.Activity;
import android.os.Bundle;
public class gogogo extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
[main.xml]
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<my.darling.gameView
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</FrameLayout>
[gameView.java]
package my.darling;
import android.content.Context;
import android.view.SurfaceView;
import android.view.SurfaceHolder;
class gameView extends SurfaceView implements SurfaceHolder.Callback
{
public gameView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int
width,
int height) {
// TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en