Android 动态壁纸触摸事件
我刚刚开始使用Android,正在制作一个简单的动态壁纸。我正在 2.1 模拟器上测试它。问题是,虽然它在您选择“设置壁纸”之前在预览屏幕中工作,但一旦您选择它作为壁纸,触摸事件似乎不会在屏幕上注册。我是否需要在清单中声明有关触摸事件的任何内容才能使其正常工作?有点困惑为什么它适用于一个而不适用于另一个。
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();
}
}
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();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
???这缝有帮助吗?
??? Does this seam to help?
我知道这个问题有点老了,但这适用于所有在谷歌搜索时偶然发现这个问题的人。请小心 setTouchEnabled 函数 - 它适用于 2.1 和 2.1,但在所有更高版本的 Android 上,它会使应用程序崩溃。
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.