我在事件onListItemClick中的listactivity中創建一個彈出窗口。現在在android中的彈出窗口大小
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);
,高度和寬度的變量被認爲是用於彈出窗口(popupcontact)的佈局的高度和寬度。但他們返回0.我想這是因爲佈局還沒有呈現。有沒有人有線索,我怎麼能控制彈出窗口的大小,而不需要使用絕對像素數?
我也面臨着同樣的問題之前
:我解決它通過調用。這是有效的,但給予較小的高度,原來的 – vignesh 2013-04-17 04:27:46
上述代碼給了我一個空指針異常。 – Amrut 2014-03-10 11:32:53