其他分享
首页 > 其他分享> > android – OnTouch在动态壁纸中不起作用

android – OnTouch在动态壁纸中不起作用

作者:互联网

嗨,我正在http://www.rbgrn.net/content/354-glsurfaceview-adapted-3d-live-wallpapers的帮助下制作动态壁纸.现在我想在主屏幕上附加触摸检测.也就是说,在设置壁纸之后,用户可以触摸壁纸,从而可以进行相应的动作.我的源代码如下.它在预览壁纸时工作正常,但在设置壁纸后却没有.

class MyEngine extends GLEngine 
{
    MyRenderer renderer;
    AnimationController animationController;
    public MyEngine() 
    {
        super();
        renderer = new MyRenderer();
        setRenderer(renderer);
        setRenderMode(RENDERMODE_CONTINUOUSLY);
    }

    @Override
    public void onCreate(SurfaceHolder surfaceHolder)
    {
        super.onCreate(surfaceHolder);

    }

    @Override
    public void onTouchEvent(MotionEvent event) 
    {
         if (event.getAction() == MotionEvent.ACTION_MOVE ) 
         {                        
            Toast.makeText(getApplicationContext(), "Move", Toast.LENGTH_SHORT).show();             
         }
         else
         if (event.getAction() == MotionEvent.ACTION_DOWN) 
         {                         
            Toast.makeText(getApplicationContext(), "Down", Toast.LENGTH_SHORT).show();             
         }           

        super.onTouchEvent(event);
    }

}

解决方法:

得到了答案!!
刚刚添加了this.setTouchEventsEnabled(true);在MyEngine构造函数中.

标签:android,live-wallpaper
来源: https://codeday.me/bug/20190629/1329177.html