在屏幕的最左侧显示ListPopupWindow
问题描述:
通过以下代码,我可以在屏幕的最左侧显示ListPopupWindow。在屏幕的最左侧显示ListPopupWindow
@Override
public View onCreateActionView() {
LayoutInflater layoutInflater = LayoutInflater.from(mContext);
final View actionItem = layoutInflater.inflate(R.layout.list_table_view_action_provider, null);
final ImageButton button = (ImageButton) actionItem.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListPopupWindow = new ListPopupWindow(mContext);
mListPopupWindow.setAnchorView(actionItem);
mListPopupWindow.setAdapter(mAdapter);
mListPopupWindow.setModal(true);
mListPopupWindow.setContentWidth(150);
// Display mListPopupWindow on most left of the screen
mListPopupWindow.setHorizontalOffset(-1000);
mListPopupWindow.setOnItemClickListener(ListTableViewActionProvider.this);
mListPopupWindow.show();
mListPopupWindow.setOnDismissListener(ListTableViewActionProvider.this);
}
});
return actionItem;
}
“mListPopupWindow.setHorizontalOffset(-1000);”太糟糕了。 是否有其他解决方案?
答
这里是ListPopupWindow例如,
View menuItemView = getActivity().findViewById(R.id.menu_filter);
ListPopupWindow popup = new ListPopupWindow(getActivity());
popup.setHorizontalOffset(-200);
popup.setVerticalOffset(-100);
popup.setAnchorView(menuItemView);
popup.setWidth(400);
popup.setModal(true);
popup.setHeight(ListPopupWindow.WRAP_CONTENT);
ListAdapter adapter = new MyAdapter(getActivity());
popup.setAdapter(adapter);
popup.show();
尝试具有最外面的布局/活性作为锚,并用0 偏移或也可以使用一个PopupWindow并给出x和y为的ViewGroup 0 – Varun 2012-03-28 11:48:20
我可以锚定在主页图标吗? – dadachi 2012-03-28 12:23:57
您可以锚定到主图标,使用'findViewById(android.R.id.home)'来获取视图。弹出窗口不会与屏幕左边缘齐平;主页图标左侧有一些边距(为“向上”可供选择的箭头腾出空间)。 – Karakuri 2013-01-07 16:54:00