2012-03-28 157 views
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.setHorizo​​ntalOffset(-1000);」太糟糕了。 是否有其他解決方案?

+1

嘗試具有最外面的佈局/活性作爲錨,並用0 偏移或也可以使用一個PopupWindow並給出x和y爲的ViewGroup 0 – Varun 2012-03-28 11:48:20

+1

我可以錨定在主頁圖標嗎? – dadachi 2012-03-28 12:23:57

+1

您可以錨定到主圖標,使用'findViewById(android.R.id.home)'來獲取視圖。彈出窗口不會與屏幕左邊緣齊平;主頁圖標左側有一些邊距(爲「向上」可供選擇的箭頭騰出空間)。 – Karakuri 2013-01-07 16:54:00

回答

-1

這裏是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(); 
相關問題