我的应用程序中有一个浮动小部件,我希望它在移动时跟随用户的手指。但只能垂直。而且不幸的是,该小部件没有移动,这是我的小部件onTouchListener的代码
@Override
public boolean onTouch(View v, MotionEvent event) {
initial_y = params.y;
initial_touch_y = event.getRawY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
press_point = System.currentTimeMillis();
return true;
case MotionEvent.ACTION_UP:
release_point = System.currentTimeMillis();
hold_range = release_point - press_point;
if (hold_range <= 200) //Handle click events..
first_layout.performClick();
return true;
case MotionEvent.ACTION_MOVE:
params.y = initial_y + (int) (event.getRawY() - initial_touch_y);
window_manager.updateViewLayout(floating_view, params);
return true;
}
return false;
}
});
有什么建议吗?