Honestly I dont know how to proceed. I looked up some feeds on this website and got a bit confused. The imageview button should be invisibly dragged at the specific location of an other image and as long as my pressed thumb relocates to the other image, a activity should be called. In an earlier version, the activity was functional but not while moving the button while it is hold down with my thumb. Hopefully someone knows an answer for this (for me very challenging question.
@Override
public boolean onTouchEvent(MotionEvent event) {
if (imageRect == null) {
imageRect = new Rect();
imageView2.getGlobalVisibleRect(imageRect);
}
int x = (int) event.getX();
int y = (int) event.getY();
if (imageRect.contains(x, y)) {
openActivity();
}
return super.onTouchEvent(event);
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
detectorCompat = new GestureDetectorCompat(this, new GestureListener());
imageViewPlayButton = findViewById(R.id.PlayButton_Image_White_Base);
imageView2 = findViewById(R.id.register_Icon_Base);
imageView3 = findViewById(R.id.navigation_Background_Image_Register);
imageView4 = findViewById(R.id.Login_Icon_Base);
imageViewPlayButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
imageView2.setVisibility(View.VISIBLE);
imageView3.setVisibility(View.VISIBLE);
imageView4.setVisibility(View.VISIBLE);
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
imageView2.setVisibility(View.INVISIBLE);
imageView3.setVisibility(View.INVISIBLE);
imageView4.setVisibility(View.INVISIBLE);
}
return true;
}
});
}