First:
onMeasure( widthMeasureSpec, mMaxChildWidth = 0= 0 modeW = 0, modeH = 0 (MeasureSpec.getMode(widthMeasureSpec) !== (MeasureSpec.getMode(heightMeasureSpec) !== childWidthMeasureSpec = childHeightMeasureSpec == (count == 0 ( i = 0; i < count; i++ View child = (child.getVisibility() ==== onLayout( changed, l, t, r, height = b - t; width = r - l; rows = count % colums == 0 ? count / colums : count / colums + 1; (count == 0 gridW = (width - margin * (colums - 1)) / colums; gridH = (height - margin * rows) / rows; left = 0 top = ( i = 0; i < rows; i++) { ( j = 0; j < colums; j++) { View child = .getChildAt(i * colums + (child == = j * gridW + j * (gridW !=|| gridH !=+ gridW, top ++= gridH +
MyGridLayout String TAG = "MyGridLayout" margin = 2; colums = 2 mMaxChildWidth = 0 mMaxChildHeight = 0 count = 0 MyGridLayout (Context context, AttributeSet attrs, (attrs! ===. GetInteger (R. styleable. myGridLayout_numColumns, 2 = (). getInteger (R. styleable. myGridLayout_itemMargin, 2 (context, attrs, 0 (context, onMeasure (widthMeasureSpec, mMaxChildWidth = 0 = 0 modeW = 0, modeH = 0 (MeasureSpec. getMode (widthMeasureSpec )! = (MeasureSpec. getMode (heightMeasureSpec )! = ChildWidthMeasureSpec = childHeightMeasureSpec = (count = 0 (I = 0; I <count; I ++ View child = (child. getVisibility () === onLayout (changed, l, t, r, height = B-t; width = r-l; rows = count % colums = 0? Count/colums: count/colums + 1; (count = 0 gridW = (width-margin * (colums-1)/colums; gridH = (height-margin * rows) /rows; left = 0 top = (I = 0; I <rows; I ++) {(j = 0; j <colums; j ++) {View child =. getChildAt (I * colums + (child = j * gridW + j * (gridW! = | GridH! = + GridW, top ++ = gridH +. adapter = size = (I = 0; I <size; I ++ onItemClick (View v, setOnItemClickListener ((. adapter = (I = 0; I <adapter. getCount (); I ++ index =View Code
Here I will download the complete demo: click me !!!