views:

85

answers:

1

I need to calculate how many items fit on the screen. I tried do it in this way

private int callculateItemsOnPage(View layout, View item) {
  if (layout == null || item == null)
   return -1;
  int itHeight = item.getHeight();
  int layHeight = layout.getHeight();
  return layHeight / itHeight;
 }

But itHeight, layHeight permanently 0.

Can anyone help me with my issue?

A: 

I had a similar problem too. I used the
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
method of the view.

@Override
protected void onMeasure(int width, int height) {
    setMeasuredDimension(MeasureSpec.getSize(width), MeasureSpec.getSize(width));
    this.size = (MeasureSpec.getSize(width)-14) / 9;
}
yaourt