Skip to content

Instantly share code, notes, and snippets.

@matux
Created October 31, 2013 23:33
Show Gist options
  • Save matux/7258910 to your computer and use it in GitHub Desktop.
Save matux/7258910 to your computer and use it in GitHub Desktop.
- final float offset = 0; // d.getIntrinsicHeight() * coverImageModel.getViewport().top;
- final float y = d.getIntrinsicHeight() - offset;
- final float e = getHeight();
- final float scale = e / y;
+ final float scaleH = getHeight() / d.getIntrinsicHeight();
+ final float scaleW = getWidth() / d.getIntrinsicWidth();
- final float w = d.getIntrinsicWidth() * scale;
- final float wd = w - d.getIntrinsicWidth();
- final float wdDiv2 = wd / 2;
+ final float wd = scaleH > scaleW ? (getWidth() / 2) - ((d.getIntrinsicWidth() * scaleH) / 2) : 0;
+ final float hd = scaleW > scaleH ? (getHeight() / 2) - ((d.getIntrinsicHeight() * scaleW) / 2) : 0;
- final RectF r1 = new RectF(0, offset, d.getIntrinsicWidth(), d.getIntrinsicHeight());
- final RectF r2 = new RectF(-wdDiv2, 0, d.getIntrinsicWidth() + wdDiv2, getHeight());
+ final RectF r1 = new RectF(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
+ final RectF r2 = new RectF(wd, hd, getWidth() - wd, getHeight() - hd);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment