Reputation: 9
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?
Upvotes: 0
Views: 1218
Reputation: 3183
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;
}
Upvotes: 1