@Override public void draw(@NonNull final Canvas canvas) { super.draw(canvas); // Only recalculate the close bounds if they are dirty if (mCloseBoundChanged) { mCloseBoundChanged = false; mClosableLayoutRect.set(0, 0, getWidth(), getHeight()); // Create the bounds for our close regions. applyCloseRegionBounds(mClosePosition, mClosableLayoutRect, mCloseRegionBounds); // The inset rect applies padding around the visible closeButton. mInsetCloseRegionBounds.set(mCloseRegionBounds); mInsetCloseRegionBounds.inset(mCloseButtonPadding, mCloseButtonPadding); // The close button sits inside the close region with padding and gravity // in the same way the close region sits inside the whole ClosableLayout applyCloseButtonBounds(mClosePosition, mInsetCloseRegionBounds, mCloseButtonBounds); mCloseDrawable.setBounds(mCloseButtonBounds); } // Draw last so that this gets drawn as the top layer. This is also why we override // draw instead of onDraw. if (mCloseDrawable.isVisible()) { mCloseDrawable.draw(canvas); } }