点击popwindow的时候,计算popwindow的宽度
可能存在需要计算未显示的view的宽度的时候,添加以下代码:
/**
* 设置pop的数据源
*/
public void showViewPopWindow() {
if (kuaiJieRukouList.size() > 0) {
int position = 0;
if (null != kuaiJieRukouList.get(0).getNavcolumns() && !TextUtils.isEmpty(kuaiJieRukouList.get(0).getNavcolumns())) {
position = Integer.parseInt(kuaiJieRukouList.get(0).getNavcolumns());
}
View contentView = LayoutInflater.from(activityContext).inflate(R.layout.home_popwindow_layout, null);
RecyclerView kuaiJieRecyclerView = (RecyclerView) contentView.findViewById(R.id.webview_recyclerview);
LinearLayoutManager manager = new LinearLayoutManager(activityContext);
manager.setOrientation(LinearLayoutManager.VERTICAL);
kuaiJieRecyclerView.setLayoutManager(manager);
PopWindowAdapter webViewAdapter = new PopWindowAdapter(activityContext, kuaiJieRukouList, new PopWindowAdapter.PopAdapterListener() {
@Override
public void onClick(BusinessEntity entity) {
if (mCustomPopWindow != null) {
mCustomPopWindow.dissmiss();
}
StartInfoActivityUtil.homeStartActivity(activityContext, entity.getUrl(), entity.getMenuLittleName(), "快捷入口");
}
});
kuaiJieRecyclerView.setAdapter(webViewAdapter);
//创建并显示popWindow
mCustomPopWindow = new CustomPopWindow.PopupWindowBuilder(activityContext)
.setView(contentView)
.size(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)//显示大小
.setFocusable(true)
.setOutsideTouchable(true)
.create();
//重点,即可拿到宽高
contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
switch (position) {
//0,1,2,3左上左下右上右下
case 0:
case 1:
mCustomPopWindow.showAsDropDown(mEntranceImage, mEntranceImage.getWidth(), -kuaiJieRukouList.size() * screenHeight / 20);
break;
case 2:
case 3:
mCustomPopWindow.showAsDropDown(mEntranceImage, -contentView.getMeasuredWidth(), -kuaiJieRukouList.size() * screenHeight / 20);
break;
default:
mCustomPopWindow.showAsDropDown(mEntranceImage, mEntranceImage.getWidth(), -kuaiJieRukouList.size() * screenHeight / 20);
break;
}
} else {
Toast.makeText(activityContext, "无快捷活动入口", Toast.LENGTH_LONG).show();
}
}
网友评论