@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); if(outBox == null){ outBox = new Box(left, top, right, bottom, strokeColor, 10); outBox.getPaint().setStrokeWidth(strokeWidth); } if(box == null){ box = new Box(left + strokeWidth, top + strokeWidth, right/2 - strokeWidth, bottom/2 - strokeWidth, loaderColor, 10); box.setDx(speed); box.setDy(speed); } }