Created
October 20, 2015 14:49
-
-
Save kmansoft/064b2cac58abe32b19fd to your computer and use it in GitHub Desktop.
Fix for Spinner.getBaseline returning wrong value on Android 5.1 (maybe 5.0+) in some cases
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
public class SpinnerWithBaseline extends Spinner { | |
public SpinnerWithBaseline(Context context, AttributeSet attr) { | |
super(context, attr); | |
} | |
@Override | |
public int getBaseline() { | |
final int children = getChildCount(); | |
int childBaseline = 0; | |
if (children > 0) { | |
View child = getChildAt(0); | |
if (child != null) { | |
childBaseline = child.getBaseline(); | |
if (childBaseline >= 0) { | |
final Drawable dr = getBackground(); | |
if (dr != null) { | |
final Rect rect = new Rect(); | |
dr.getPadding(rect); | |
childBaseline += rect.top; | |
} | |
return childBaseline; | |
} | |
} | |
} | |
final int superBaseline = super.getBaseline(); | |
return superBaseline; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment