Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Popup window size in android

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?

like image 342
Bostjan Avatar asked Jun 10 '10 12:06

Bostjan


People also ask

How do I change the pop-up window size in Android?

You will be able to change the size by using the pinch-zoom gesture.

What is pop-up window Android?

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.

How do I pass custom layout to popupMenu?

OnClickListener() { @Override public void onClick(View view) { PopupMenu popupMenu = new PopupMenu(Sample1. this, view); popupMenu. setOnMenuItemClickListener(Sample1. this); popupMenu.


1 Answers

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()

like image 92
Yann Avatar answered Nov 15 '22 20:11

Yann