I am developing an application for Android and I am using a popup window when the user clicks a specific menu bar object(consisting of small images lined up horizontally) on
Sample example:
ScrollView scrollView = new ScrollView(context);
popupWindow.setContentView(scrollView);
scrollView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
int he=scrollView.getMeasuredHeight();
popupWindow.showAsDropDown(items,0, -items.getHeight()-he);
The one you want to use is showAtLocation(...)
. You specify the anchor view (the one the user clicks), and position it relative to that via the gravity
parameter and offsets. Think of the gravity
parameter like the PopupWindow
is almost like a child view and the parent view is like a container layout.
You should be able to put Gravity.LEFT | Gravity.TOP
as the parameter.