MaterialSpinner
MaterialSpinner copied to clipboard
No attribute for Dropdown width?
the dropdown width is taking the whole screen. how can i control it?

<com.cepheuen.elegantnumberbutton.view.ElegantNumberButton android:id="@+id/elegantNumberButton" android:layout_width="84dp" android:layout_height="wrap_content" android:elevation="4dp" app:backGroundColor="#4657B8" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:textSize="6sp">
</com.cepheuen.elegantnumberbutton.view.ElegantNumberButton>
I think that option is no implemented. I had to modify source code to get it working:
MaterialSpinner.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// popupWindow.setWidth(MeasureSpec.getSize(widthMeasureSpec));
// Popup width hardcoded.
popupWindow.setWidth(250);
popupWindow.setHeight(calculatePopupWindowHeight());
...
public void expand() {
if (!hideArrow) {
animateArrow(true);
}
nothingSelected = true;
// Popup position hardcoded.
popupWindow.showAsDropDown(this, -100, 0);
}
@subrud What is ElegantNumberButton?
I set the layout_width to 100dp to test this and the PopupWindow matched the MaterialSpinner width. @enekonieto are you sure you need to hardcode the width there?
I was thinking a fix for this would be to set the PopupWindow width when the spinner is laid out:
getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override public void onGlobalLayout() {
spinner.getPopupWindow().setWidth(spinner.getWidth());
}
});
However, it is working for me; I cannot reproduce this.