问题
I've just started with Android, I'm making a simple Live wallpaper. I'm testing it on a 2.1 emulator. The trouble is while it works in the preview screen before you choose "Set Wallpaper" the touch events don't appear to register on the screen once you've selected it as a wallpaper. Do I need to state anything in the manifest about touch events or so to get it to work? Little bit confused why it would work in one and not the other.
public void handleTouchEvent(MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_UP) {
//add new BulletHole
int x = (int)event.getX();
int y = (int)event.getY();
synchronized(holes) {
holes.add(new BulletHole(x,y));
}
}
this.pause = false;
synchronized(this) {
notify();
}
}
回答1:
@Override
public void onCreate(SurfaceHolder surfaceHolder) {
super.onCreate(surfaceHolder);
// By default we don't get touch events, so enable them.
setTouchEventsEnabled(true);
}
??? Does this seam to help?
回答2:
I know that this question is a bit old, but this goes for all those who stumbled on this while googling. Be careful with the setTouchEnabled function - it works perfectly for 2.1 and 2.1, but on all higher versions of Android it crashes the app.
来源:https://stackoverflow.com/questions/3006916/android-live-wallpaper-touch-events