Skip to content

Instantly share code, notes, and snippets.

@patrick-elmquist
Created July 12, 2017 11:36
Show Gist options
  • Save patrick-elmquist/69a048a2069e61430a79071a35907bcd to your computer and use it in GitHub Desktop.
Save patrick-elmquist/69a048a2069e61430a79071a35907bcd to your computer and use it in GitHub Desktop.
Frame by frame #4
public class SpinnerLoaderView extends View {
private final RectF mArcBounds = new RectF();
private final Paint mPaint = new Paint();
// ...
@Override
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
super.onSizeChanged(width, height, oldWidth, oldHeight);
final int smallestSide = Math.min(width, height);
mPaint.setStrokeWidth(smallestSide * 0.05f);
// When drawing a stroked line at an X,Y position it's always the
// the center of the brush that's positioned there. This means that
// if the position is set the one of view edges, half the stroke width
// will be drawn outside of the view. To counter this, add half the
// stroke width as a padding.
final float paintPadding = mPaint.getStrokeWidth() / 2f;
// Also apply any padding set in the XML/using setPadding(...)
mArcBounds.set(
paintPadding + getPaddingLeft(),
paintPadding + getPaddingTop(),
width - paintPadding - getPaddingRight(),
height - paintPadding - getPaddingBottom()
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment