Popup window size in android

Posted by Bostjan on Stack Overflow See other posts from Stack Overflow or by Bostjan
Published on 2010-06-10T12:01:54Z Indexed on 2010/06/10 13:02 UTC
Read the original article Hit count: 257

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about android

Related posts about layout