Skip to content

Instantly share code, notes, and snippets.

@easternHong
Created December 8, 2015 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save easternHong/2cca7227fb699f6b4638 to your computer and use it in GitHub Desktop.
Save easternHong/2cca7227fb699f6b4638 to your computer and use it in GitHub Desktop.
android view layout children
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int row, col, left, top;
for (int i=0; i < getChildCount(); i++) {
row = i / mColumnCount;
col = i % mColumnCount;
View child = getChildAt(i);
left = col * child.getMeasuredWidth();
top = row * child.getMeasuredHeight();
child.layout(left, top, left + child.getMeasuredWidth(), top + child.getMeasuredHeight());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment