I'm creating a popup window in a listactivity in the event onListItemClick.
LayoutInflater inflater = (LayoutInflater)
this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View pop = inflater.inflate(R.layout.popupcontact, null, false);
ImageView atnot = (ImageView)pop.findViewById(R.id.aNot);
height = pop.getMeasuredHeight();
width = pop.getMeasuredWidth();
Log.e("pw","height: "+String.valueOf(height)+", width: "+String.valueOf(width));
atnot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pw.dismiss();
}
});
pw = new PopupWindow(pop, width, height, true);
// The code below assumes that the root container has an id called 'main'
//pw.showAtLocation(v, Gravity.CENTER, 0, 0);
pw.showAsDropDown(v, 10, 5);
Now, the height and width variables were supposed to be height and width of the layout used for the popup window (popupcontact). But they return 0. I guess that is because the layout isn't rendered yet. Does anyone have a clue, how can I control the size of the popup window without needing to use absolute pixel numbers?
You will be able to change the size by using the pinch-zoom gesture.
android.widget.PopupWindow. This class represents a popup window that can be used to display an arbitrary view. The popup window is a floating container that appears on top of the current activity.
OnClickListener() { @Override public void onClick(View view) { PopupMenu popupMenu = new PopupMenu(Sample1. this, view); popupMenu. setOnMenuItemClickListener(Sample1. this); popupMenu.
I had a similar issue. I solved it by calling:
pop.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
before getting the size of the layout with getMeasuredHeight() and getMeasuredWidth()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With