Skip to content

Instantly share code, notes, and snippets.

@kmansoft
Created October 20, 2015 14:49
Show Gist options
  • Save kmansoft/064b2cac58abe32b19fd to your computer and use it in GitHub Desktop.
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
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