Created
September 29, 2020 18:52
-
-
Save matthewmorrone/aa2373846f5bd4a4993994ebf938d167 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void layoutAndShowPopupWindow(Key key, int xPosition) { | |
| popupWindow = new PopupWindow(popupView, | |
| LinearLayout.LayoutParams.WRAP_CONTENT, | |
| LinearLayout.LayoutParams.WRAP_CONTENT); | |
| popupWindow.setClippingEnabled(false);// <-- let popup display above keyboard | |
| int location[] = new int[2]; | |
| key.getLocationInWindow(location); | |
| int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); | |
| popupView.measure(measureSpec, measureSpec); | |
| int popupWidth = popupView.getMeasuredWidth(); | |
| int spaceAboveKey = key.getHeight() / 4; | |
| int x = xPosition - popupWidth / popupView.getChildCount() / 2; | |
| int y = location[1] - popupView.getMeasuredHeight() - spaceAboveKey; | |
| popupWindow.showAtLocation(key, Gravity.NO_GRAVITY, x, y); | |
| // using popupWindow.showAsDropDown(key, 0, yOffset) might be | |
| // easier than popupWindow.showAtLocation() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment