본문 바로가기
프로그래밍 놀이터/안드로이드, Java

[android] 특정 위치에 popup window 띄우기

by 돼지왕 왕돼지 2017. 7. 12.
반응형

 [android] 특정 위치에 popup window 띄우기


http://frogermcs.github.io/InstaMaterial-concept-part-4-feed-context-menu/

Action, addonpredrawlistener, Android, animation, Bottom, Duration, getLocationOnScreen, LinearLayout, listener callback, Menu, menu 위치, overshootinterpolator, popup window, pre draw listener, scalex, scaley, setpivotx, setpivoty, settranslationx, settranslationy, Top, View, ViewTreeObserver, X, y, [android] 특정 위치에 popup window 띄우기, 기준점, 터치된 뷰의 위치, 특정 위치, 해지


-

꼭 popup window 를 띄우지 않아도, LinearLayout 등을 통해서도 popup window 형태를 충분히 띄울 수 있다.


Context menu screenshot


-

메뉴를 표시하는 LinearLayout 를 하나 만든다.



-

menu 를 표시하는 action 이 들어오면, 메뉴 view 를 만들고, ViewTreeObserver 에 addOnPreDrawListener 를 등록한다.



-

listener callback 에서는 먼저 pre draw listener 를 해지해주고, menu 의 위치를 잡아준다.



-

위치를 잡는것은, 기준점이 되는 위치(터치된 뷰의 위치)를 getLocationOnScreen 함수를 통해 얻고,

해당 위치에서 약간의 계산을 통해 menu 가 표시될 x, y 를 잡아준다.

이 때 setTranslationX, setTranslationY 를 사용한다.



-

등장 animation 은 setPivotX 와 setPivotY 를 통해, x 축으로는 click view 의 중앙지점, y축으로는 click view 의 top 혹은 bottom  을 잡아주고, scaleX 와 scaleY 를 0.1f 에서 1.f 로 150ms 정도 duration 으로 animation 을 해준다.

이 때 튕기는 효과를 조금 주려면 OvershootInterpolator 를 주면 된다.




반응형

댓글