It appears that a spinner is sized to the longest item given in its adapter. This is a good behavior for the majority of cases, but it is undesirable in my particular case.
Is this possible to turn this off? My guess is no, by looking at Spinner.onMeasure() in the source, but figured I'd ask.
I achieved this now by subclassing Spinner:
public class SpinnerWrapContent extends IcsSpinner {
private boolean inOnMeasure;
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
inOnMeasure = true;
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
inOnMeasure = false;
}
public boolean isInOnMeasure() {
return inOnMeasure;
}
}
Then in my SpinnerAdapter's getView(), I used the currently selected position if I am called from onMeasure():
public View getView(int position, View convertView, ViewGroup parent) {
View view;
if (convertView != null)
view = convertView;
else {
int fixedPosition = (spinner.isInOnMeasure() ? spinner.getSelectedItemPosition() : position);
// Here create view for fixedPosition
}
return view;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With