Search code examples
javaandroidlauncher

How to make a "swipe up" function like in many custom launchers?


I'm doing my own custom launcher for Android at the moment. Everything works so far. But there is one point where I need help. I would like to do something like a swipe up on the home screen to display all installed apps. Therefore I do not want to start a new activity, cause of the delay. Maybe it's possible to change the layout file with something like an animation when a gesture is detected? And how would I detect the swipe?


Solution

  • It's really easy to detect motion:

    someViewLikeLinearLayout.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        //put finger on screen
                        return true;
                    case MotionEvent.ACTION_UP:
                        //release the finger
                        return true;
    
                }
    
            }
        });
    

    Just switch event and you can get many actions via MotionEvent Good luck!