private void init() {
LinearLayout view = new LinearLayout(context);
view.setOrientation(LinearLayout.VERTICAL);
view.setGravity(Gravity.CENTER_HORIZONTAL);
view.setBackgroundColor(Color.rgb(224, 224, 224));
view.setPadding(1, 1, 1, 1);
listView = new ListView(context);
adapter = new PopAdapter();
listView.setAdapter(adapter);
listView.setCacheColorHint(0x00000000);
listView.setDivider(new ColorDrawable(0xe0e0e0));
listView.setDividerHeight(1);
if (this.config != null && this.config.getBackground_resId() != 0) {
listView.setBackgroundResource(this.config.getBackground_resId());
} else {
listView.setBackgroundColor(Color.rgb(224, 224, 224));
}
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
view.addView(listView, layoutParams);
if (this.config != null && this.config.getWidth() > 0) {
popupWindow = new PopupWindow(view, this.config.getWidth(),
LayoutParams.WRAP_CONTENT);
} else {
// 为了自适应长度添加
TextView text = new TextView(context);
text.setHeight(0);
text.setText("图片的空" + getMostItemText());
text.setTextSize(16);
text.setPadding(5, 5, 5, 5);
view.addView(text, layoutParams1);
popupWindow = new PopupWindow(view, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
}
if (dismissListener != null) {
popupWindow.setOnDismissListener(dismissListener);
}
// 这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景(很神奇的)
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
// 使其聚集
popupWindow.setFocusable(true);
// 设置允许在外点击消失
popupWindow.setOutsideTouchable(true);
// 刷新状态
popupWindow.update();
popupWindow.setTouchInterceptor(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
popupWindow.dismiss();
return true;
}
return false;
}
});
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// 获取该行的数据
PopMenuItem popMenuItem = (PopMenuItem) listView.getAdapter()
.getItem(arg2);
if (popMenuItem.listener != null) {
popMenuItem.listener.onItemClick();
dismiss();
}
}
});
}
PopMenu.java 文件源码
java
阅读 26
收藏 0
点赞 0
评论 0
项目:EntboostIM
作者:
评论列表
文章目录