Skip to content

Instantly share code, notes, and snippets.

@rongi
Created April 1, 2014 18:22
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 rongi/9919963 to your computer and use it in GitHub Desktop.
Save rongi/9919963 to your computer and use it in GitHub Desktop.
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int width = r - l;
final int height = b - t;
final int bigImageViewHeight = Math.round(0.4f * height);
layoutChild(bigImageView,
Math.round(0.1f * width),
0,
Math.round(0.8f * width),
bigImageViewHeight);
final int bigImageViewCenterVertical = bigImageViewHeight / 2;
final int smallImageViewHeight = smallImageView.getMeasuredHeight(); // for example
layoutChild(smallImageView,
Math.round(0.3f * width),
bigImageViewCenterVertical - smallImageViewHeight / 2,
Math.round(0.4f * width),
smallImageViewHeight);
// etc
}
private static void layoutChild(View view, int left, int top, int width, int height) {
view.layout(left, top, left + width, top + height);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment