我必须显示弹出窗口。我已经做到了,但我无法设置此弹出窗口的位置。 我必须在 friend 标签下方设置弹出窗口。
.
代码:
_spinner = (Spinner) view.findViewById(R.id.group_spinner);
_groupAdaptor = new ArrayAdapter(getActivity(),
android.R.layout.simple_spinner_dropdown_item, _itemGroupList);
_spinner.setAdapter(_groupAdaptor);
_spinner.setOnItemSelectedListener(this);
然后点击我调用如下方法:
_spinner.performClick();
最佳答案
使用我的工作代码..
Rect r = locateView(v);
final PopupWindow popup = new PopupWindow(getActivity());
popup.setAnimationStyle(R.style.animation);
popup.setContentView(layout);
popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
popup.setWidth(getActivity().getWindowManager().getDefaultDisplay().getWidth() / 2);
popup.setFocusable(true);
popup.setBackgroundDrawable(new BitmapDrawable());
popup.showAtLocation(layout, Gravity.TOP | Gravity.LEFT, r.right, r.bottom);
public static Rect locateView(View v) {
int[] loc_int = new int[2];
if (v == null)
return null;
try {
v.getLocationOnScreen(loc_int);
} catch (NullPointerException npe) {
return null;
}
Rect location = new Rect();
location.left = loc_int[0];
location.top = loc_int[1];
location.right = loc_int[0] + v.getWidth();
location.bottom = loc_int[1] + v.getHeight();
return location;
}
关于android - 显示设置弹出窗口的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19159280/