菜单
private void showPopupWindow2(View view1) {
View parent = ((ViewGroup) this.findViewById(android.R.id.content)).getChildAt(0);
//自定义布局,显示内容
View view = LayoutInflater.from(this).inflate(R.layout.camera_pop_menu, null);
LinearLayout small=(LinearLayout)view.findViewById(R.id.small);
small.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
int width= (int) (ScreenUtils.getScreenWidth(answer.getContext())*0.68);//菜单的宽度
int height= (int) (ScreenUtils.getScreenHeight(answer.getContext())*0.35);、、菜单的高度
PopupWindow window = new PopupWindow(view,height , width, true);
window.setTouchable(true);
window.setTouchInterceptor(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return false;
//这里如果返回true的话,touch事件将被拦截
//拦截后 PoppWindow的onTouchEvent不被调用,这样点击外部区域无法dismiss
}
});
//(注意一下!!)如果不设置popupWindow的背景,无论是点击外部区域还是Back键都无法弹框
ColorDrawable dw = new ColorDrawable(Color.WHITE);
window.setBackgroundDrawable(dw);
window.showAtLocation(parent, Gravity.TOP | Gravity.END, 0, 230);偏移量
window.showAsDropDown(view1);
}