自从我不久前拿到我的 Droid X 之后,我就一直在琢磨研究 Android SDK 的想法,并且最近才采取行动。我在 Eclipse 中安装了 ADT 插件,下载并安装了 Android SDK (Rev. 11),并尝试了一些东西。我想尝试 2d 图形,因为它们与我在工作中花费的时间(嵌入式系统开发)大相径庭。
我尝试按照此处的教程进行操作,但由于实现的两个接口存在一些错误,因此无法构建。我正在尝试在 64 位 Windows 7 机器上构建 2.3.3。我将包含下面的代码,重要的警告是我不是一个典型的 Java 程序员,一些明显的东西很容易让我逃脱。
可绘制面板.java
package com.android.tutorial;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public abstract class DrawablePanel
extends SurfaceView
implements SurfaceHolder.Callback, ISurface {
private AnimationThread thread;
public DrawablePanel(Context context) {
super(context);
getHolder().addCallback(this);
this.thread = new AnimationThread(getHolder(), this);
}
@Override
public void onDraw(Canvas canvas) {
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
thread.setRunning(true);
thread.start();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
boolean retry = true;
thread.setRunning(false);
while (retry) {
try {
thread.join();
retry = false;
} catch (InterruptedException e) {
// we will try it again and again...
}
}
}
}
ISurface.java
package com.android.tutorial;
import android.graphics.Canvas;
public interface ISurface {
void onInitialize();
void onDraw(Canvas canvas);
void onUpdate(long gameTime);
}
Android教程.java
package com.android.tutorial;
import android.app.Activity;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.os.Bundle;
public class AndroidTutorial extends Activity {
AnimatedSprite animation = new AnimatedSprite();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new AndroidTutorialPanel(this));
}
class AndroidTutorialPanel extends DrawablePanel {
public AndroidTutorialPanel(Context context) {
super(context);
}
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
AndroidTutorial.this.animation.draw(canvas);
}
@Override
public void onInitialize() {
AndroidTutorial.this.animation.Initialize(
BitmapFactory.decodeResource(
getResources(),
R.drawable.explosion),
32, 32, 14, 7);
}
@Override
public void onUpdate(long gameTime) {
AndroidTutorial.this.animation.Update(gameTime);
}
}
}
我在DrawablePanel.java
surfaceChanged()、surfaceCreated() 和 surfaceDestroyed() 的定义中遇到以下错误:
The method [name of function mentioned above](SurfaceHolder) of type DrawablePanel must override a superclass method.
对于onInitialize
和onUpdate
in也是一样的AndroidTutorial.java
。我迷路了,因为我可以在工作中复制/粘贴相同的东西(SDK 的第 10 版),没有错误。有什么想法吗?