I am using a GridLayoutView, and I am adding Images to it. I want there to be 3 columns and spacing between the items. So far, everything is working, but when adding the images, I want to get the width of the Item. I could use parent.getWidth() / 3
but I need the spacing to be calculated into the width of an Item. Is there an easy way to get the inner size of each item?
Asked
Active
Viewed 18 times
0

Ian Rehwinkel
- 2,486
- 5
- 22
- 56
1 Answers
1
You can override the ImageView's onMeasure method to obtain the width and height of the view:
onMeasure(int widthMeasureSpec, int heightMeasureSpec){
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
}
More on the rendering procedure.
This thread may be useful to you as well.

Danny Buonocore
- 3,731
- 3
- 24
- 46