I have a button that should display a popup. And the popup should be aligned on the right side of the button. This is how I do it.
button.setOnClickListener( new View.OnClickListener() { @Override public void onClick( final View view ) { if(popup == null) { final View view = getLayoutInflater().inflate(R.layout.popup, null); popup = new PopupWindow(view); } if(popup.isShowing()) { popup.dismiss(); } else { popup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED); popup.setFocusable(true); popup.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); popup.showAsDropDown(button, 0, 0); } } } );
This code works fine, but the popup is aligned with the left side of the button. Is there an easy way to change the gravity of PopupWindow?
source share