Я использую PopupWindow для отображения некоторых подкатегорий при нажатии на элемент ListView.Я использую один и тот же макет для ListView
строк (категорий) и для PopupWindow (категорий).
Моя проблема заключается в том, что я установил ширину моего PopupWindow
в соответствии с шириной моего представления элемента строки, но когда он отображается, он немного уже, с какой-то границей.
На скриншоте ниже я поместил PopupWindow поверх ListView, чтобы увидеть разницу
Почему это так?меньше?Как я могу удалить эту границу?
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);
}