I use StickyGridHeaders library to create an Gridview like snapfish. Here is my expected layout:
I show a popup windows when touching a button on header view (red arrow) instead of check box. The problem is my popup window always display wrong position. From debugging window, I can see it has the same location with sticky header, but I turned off sticky header for my gridview by using StickyGridHeadersGridView.setAreHeadersSticky(false);
Here is my adapter header:
public View getHeaderView(final int position, View convertView, ViewGroup parent) {
final HeaderViewHolder viewHolder;
if(convertView == null){
convertView = inflater.inflate(R.layout.item_header_gallery, null);
viewHolder = new HeaderViewHolder();
viewHolder.tvImagePrice = (TextView) convertView.findViewById(R.id.tvImagePrice);
viewHolder.btnTouch = (Button) convertView.findViewById(R.id.btnTouch);
convertView.setTag(viewHolder);
}else{
viewHolder = (HeaderViewHolder) convertView.getTag();
}
ImageGroup item = headers.get(position);
viewHolder.tvImagePrice.setText(item.getPriceString());
viewHolder.btnTouch.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int[] location = new int[2];
viewHolder.btnTouch.getLocationOnScreen(location);
// location always is [905,59] for every header item
System.out.println("location = " + location[0] + "," + location[1]);
// show popup on this location:
mPopupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0], location[1]);
}
});
return convertView;
}
If I show a popup in child view instead of header, the popup window show correctly. Is there something wrong?
Looks like you are getting the windows location inside the other window and not the location on the entire screen. Take a look at this question for more details: getLocationOnScreen() vs getLocationInWindow()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With