Проблема с шириной / стилем PopupWindow - PullRequest
2 голосов
/ 22 марта 2012

Я использую PopupWindow для отображения некоторых подкатегорий при нажатии на элемент ListView.Я использую один и тот же макет для ListView строк (категорий) и для PopupWindow (категорий).

Моя проблема заключается в том, что я установил ширину моего PopupWindow в соответствии с шириной моего представления элемента строки, но когда он отображается, он немного уже, с какой-то границей.

На скриншоте ниже я поместил PopupWindow поверх ListView, чтобы увидеть разницу

Почему это так?меньше?Как я могу удалить эту границу?

enter image description here

listView.setOnItemClickListener (...)

listView.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> a, View v, int position, long id) {        

            showPopup(HomeActivity.this, layout_base, v, position);
        }
    }
});

showPopup (...)

public void showPopup(Context context, View parent, View view, int position){

    /*
     * Compute popup position and size
     */

    int[] itemPosition = new int[2];
    view.getLocationOnScreen(itemPosition);

    int item_width = view.getWidth();
    int item_height = view.getHeight();

    int nChildren = GlobalVars.menuItemArray[position].children.size();

    int popup_height = item_height * nChildren; 

    /*
     * Build the view
     */

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    LinearLayout popupContainer = new LinearLayout(context);
    popupContainer.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    popupContainer.setOrientation(LinearLayout.VERTICAL);

    LayoutParams params;

    params = new LayoutParams(item_width, item_height);
    popupContainer.setOrientation(LinearLayout.VERTICAL); 

    for(int i=0; i<nChildren; i++){

        RelativeLayout menu_row = (RelativeLayout) inflater.inflate(R.layout.menu_row, null);        

        popupContainer.addView(menu_row, params);
    }

    mPopup.setContentView(popupContainer);
    mPopup.setHeight(popup_height);
    mPopup.setWidth(item_width);

    mPopup.showAtLocation(parent, Gravity.TOP|Gravity.LEFT, 0, 0);         

}

1 Ответ

7 голосов
/ 04 апреля 2012

Мне пришлось удалить фон PopupWindow, используя:

mPopup.setBackgroundDrawable(new BitmapDrawable());
...