Search code examples
androidbuttononlongclicklistenerlong-click

Pinterest long click on image and display button


I dont know how to achieve this effect on long click. Long click on image in pinterest android app. Three buttons sliding from red ring to left.

Edit: like this https://github.com/GnosisHub/GHContextMenu

enter image description here


Solution

  • Put 3 invisible ImageViews in the layout (these are the buttons). Set an onLongCLickListener on the larger ImageView. When the long click occurs, make the three buttons visible and animate them into position with ObjectAnimator or ViewPropertyAnimator. When you want to dismiss the buttons, animate them back to where they started and make them invisible again.

    You will have to do some math and figure out how far to translate (move) the buttons in the X and Y directions, and it will be different for each button. I suggest placing the buttons where you want them to be when they are visible. When you want to animate them, calculate the difference between their current position and the center of the larger image (or from the touch location). Then you set translation X and translation Y to those values and animate them back to 0.