I have a custom view that can be dragged around the screen and when tapped it will display another view, everything works fine when it is used in the emulator. But when on a real device the custom view does not show the new view on click. And I am struggling to understand why.
I think this is where the problem is: the other view only shows on tap when I put the view on the leftmost side of the screen, but if I change the sign > to < now the view can be opened from the rightmost side but not on the left.
case MotionEvent.ACTION_MOVE:
if(motionEvent.getRawX() > 120 && motionEvent.getRawY() > 120){
params.x = initialX + (int) (motionEvent.getRawX() - initialTouchX);
params.y = initialY + (int) (motionEvent.getRawY() - initialTouchY);
mWindowManager.updateViewLayout(entireLayout, params);
moving = true;
}
This is the complete code:
collapsedLayout.setOnTouchListener(new View.OnTouchListener() {
private int initialX;
private int initialY;
private float initialTouchX;
private float initialTouchY;
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()){
case MotionEvent.ACTION_DOWN:
initialX = params.x;
initialY = params.y;
initialTouchX = motionEvent.getRawX();
initialTouchY = motionEvent.getRawY();
return true;
case MotionEvent.ACTION_MOVE:
if(motionEvent.getRawX() > 120 && motionEvent.getRawY() > 120){
params.x = initialX + (int) (motionEvent.getRawX() - initialTouchX);
params.y = initialY + (int) (motionEvent.getRawY() - initialTouchY);
mWindowManager.updateViewLayout(entireLayout, params);
moving = true;
}
return true;
case MotionEvent.ACTION_UP:
if(moving){
if (params.x > 0) {
params.x = (int) dpWidth;
} else if (params.x < 0) {
params.x = (int) dpWidth * -1;
}
mWindowManager.updateViewLayout(entireLayout, params);
moving = false;
}else {
collapsedLayout.setVisibility(View.GONE);
expandedLayout.setVisibility(View.VISIBLE);
}
return true;
}
return false;
}
});
Thanks in advance for any help!