Object appears at start (press) the Onlongclicklistener event and disappears at end (drop)

Asked

Viewed 17 times

0

I’m thinking of a way to make a view with the attribute visibility: gone be visible when you click long click on the screen and disappear as soon as you drop, similar to and done with Instagram. Someone has an idea how to do?

App Instagram

1 answer

0

You can do this way using the event setOnTouchListener, within this event, you will come across the method onTouch that will rescue the action that the user is using, the ACTION_DOWN, for when the user is holding the button and ACTION_UP, for when the user releases the button:

my_btn.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                // Abra sua View

            } else if (event.getAction() == MotionEvent.ACTION_UP) {
               // Feche sua View

            }
            return false;
        }
    });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.