现在的位置: 首页 > 综合 > 正文

自定义popupWindow显示位置

2013年10月11日 ⁄ 综合 ⁄ 共 781字 ⁄ 字号 评论关闭

int[] arrayOfInt = new int[2];  //用于存放点击位置坐标
v.getLocationInWindow(arrayOfInt); //V代表View
int i = arrayOfInt[0] - (v.getBottom() + v.getBottom()); // i 代表显示的X坐标
int j = arrayOfInt[1] + v.getBottom() + 5;  // j 代表Y坐标  (可以根据自己的需求定义)
View view = View.inflate(this, R.layout.yl_popup_repair, null);
Button openCamera = (Button) view.findViewById(R.id.yi_select2);
Button openMyAlbum = (Button) view.findViewById(R.id.yi_select3);
Button myList = (Button) view.findViewById(R.id.yi_select1);
myList.setVisibility(View.GONE);

openCamera.setOnClickListener(this);
openMyAlbum.setOnClickListener(this);
Const.popupWindow = new PopupWindow(view,LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
Const.popupWindow.setAnimationStyle(R.style.ystyle_popupAnimation); //添加动画
Const.popupWindow.showAtLocation(view, Gravity.LEFT| Gravity.TOP, i, j); //在指定位置显示

抱歉!评论已关闭.