5
通過以下代碼,我可以在屏幕的最左側顯示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);」太糟糕了。 是否有其他解決方案?
嘗試具有最外面的佈局/活性作爲錨,並用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