Android 动态壁纸触摸事件

发布于 2024-09-04 12:18:38 字数 559 浏览 0 评论 0原文

我刚刚开始使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

又怨 2024-09-11 12:18:38
    @Override
    public void onCreate(SurfaceHolder surfaceHolder) {
        super.onCreate(surfaceHolder);

        // By default we don't get touch events, so enable them.
        setTouchEventsEnabled(true);
    }

???这缝有帮助吗?

    @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?

念﹏祤嫣 2024-09-11 12:18:38

我知道这个问题有点老了,但这适用于所有在谷歌搜索时偶然发现这个问题的人。请小心 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文