您好我正在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);
}
}
答案 0 :(得分:3)
得到了答案! 刚刚添加了this.setTouchEventsEnabled(true);在MyEngine构造函数中。