Skip to content

Instantly share code, notes, and snippets.

@brucetoo
Created January 8, 2016 06:56
Show Gist options
  • Select an option

  • Save brucetoo/766a9860c105e9f609ba to your computer and use it in GitHub Desktop.

Select an option

Save brucetoo/766a9860c105e9f609ba to your computer and use it in GitHub Desktop.
ListPopwindow正确适配的姿势(解决某些手机无法响应点击事件)
private void initPopupWindow() {
popupWindow = new ListPopupWindow(getActivity());
//为了适配某些手机而采用此种做法
popupWindow.setAdapter(new QuickAdapter<String>(getActivity(),R.layout.xxxxx, Arrays.asList(tabs)) {
@Override
protected void convert(BaseAdapterHelper helper, final String item) {
helper.setText(R.id.xxx),item);
helper.setOnClickListener(R.id.xxx, new View.OnClickListener() {
@Override
public void onClick(View view) {
popupWindow.dismiss();
//在此处理点击的响应
}
});
}
});
//popwindow 宽度
popupWindow.setWidth(DensityUtil.dip2px(getActivity(), 100));
//popwindow 高度
popupWindow.setHeight(ListPopupWindow.WRAP_CONTENT);
//popwindow 显示的触发 view
popupWindow.setAnchorView(showSpinner);
// 模态模式
popupWindow.setModal(false);
//背景
popupWindow.setBackgroundDrawable(R.drawable.xxxx);
//水平移动的距离
popupWindow.setHorizontalOffset(-(int) (tab.getTextSize() * 2f));
//垂直移动的距离
popupWindow.setVerticalOffset(DensityUtil.dip2px(getActivity(), 2));
//在某些魅族手机上不能响应点击事件,即使加上了 android:descendantFocusability="blocksDescendants"
//改方法在某些手机上根本不响应点击事件
popupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment