Bos*_*jan 10 size layout android popup
我正在onListItemClick事件中的listactivity中创建一个弹出窗口.
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);
Run Code Online (Sandbox Code Playgroud)
现在,高度和宽度变量应该是用于弹出窗口(popupcontact)的布局的高度和宽度.但他们返回0.我想这是因为布局尚未呈现.有没有人有线索,如何控制弹出窗口的大小而不需要使用绝对像素数?
Yan*_*ann 43
我有类似的问题.我通过调用解决了它:
pop.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
Run Code Online (Sandbox Code Playgroud)
在使用getMeasuredHeight()和getMeasuredWidth()获取布局大小之前
| 归档时间: |
|
| 查看次数: |
31380 次 |
| 最近记录: |