Created
September 1, 2016 05:21
-
-
Save noaht11/0eb887ee1543a417421f4e4bd69b39b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void updatePadding() { | |
boolean chipsArePresent = !getAllChips().isEmpty(); | |
if (!chipsArePresent && mUsingDefaultPadding) { | |
mUsingDefaultPadding = false; | |
Paint paint = getPaint(); | |
Paint.FontMetricsInt fm = paint.getFontMetricsInt(); | |
int textHeight = fm.descent - fm.ascent; | |
// Calculate how tall the view should be if there were chips | |
int newTextHeight = mChipHeight + (mChipVerticalSpacing != -1 ? mChipVerticalSpacing : 0); | |
// We need to add half our missing height above and below the text by increasing top and bottom padding | |
int paddingAdjustment = (newTextHeight - textHeight) / 2; | |
super.setPadding(getPaddingLeft(), mDefaultPaddingTop + paddingAdjustment, getPaddingRight(), mDefaultPaddingBottom + paddingAdjustment); | |
} else if (chipsArePresent && !mUsingDefaultPadding) { | |
// If there are chips we can revert to default padding | |
mUsingDefaultPadding = true; | |
super.setPadding(getPaddingLeft(), mDefaultPaddingTop, getPaddingRight(), mDefaultPaddingBottom); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment