Android的动态壁纸触摸事件壁纸、事件、动态、Android

2023-09-06 22:32:04 作者:今夜太冷不宜私奔

我刚开始与Android,我正在做一个简单的动态壁纸。我在一个2.1模拟器测试它。麻烦的是,同时它的工作原理在preVIEW屏幕上选择之前设置壁纸触摸事件不会出现在屏幕上注册,一旦你选择了它作为墙纸。我需要在清单注明任何​​有关触摸事件左右得到它的工作?有点困惑,为什么它会工作在一个,而不是其他。

 公共无效handleTouchEvent(MotionEvent事件){
    如果(event.getAction()== MotionEvent.ACTION_UP){
        //添加新BulletHole
        INT X =(int)的event.getX();
        INT Y =(INT)event.getY();
        同步(孔){
            holes.add(新BulletHole(X,Y));
        }
    }

    this.pause = FALSE;
    同步(本){
        通知();
    }
}
 

解决方案

  @覆盖
    公共无效的onCreate(SurfaceHolder surfaceHolder){
        super.onCreate(surfaceHolder);

        //默认情况下,我们没有得到触摸事件,所以启用它们。
        setTouchEventsEnabled(真正的);
    }
 

???这是否缝帮助?

动态壁纸的天花板 神器 Wallpaper Engine 终于上线 Android 版了

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();
    }
}

解决方案

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