Android Spinner Size very large

我怕爱的太早我们不能终老 提交于 2019-12-04 02:55:32

Spinner have max width his items, but at most a parent width (on layout_width = wrap_content). You may create CustomSpinner class in org.holoeverywhere.widget package and override method measureContentWidth:

@Override
int measureContentWidth(SpinnerAdapter adapter, Drawable background) {
    if (adapter == null) {
        return 0;
    }
    View view = adapter.getView(getSelectedItemPosition(), null, this);
    if (view.getLayoutParams() == null) {
        view.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
    }
    view.measure(MeasureSpec.makeMeasureSpec(0,
            MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0,
            MeasureSpec.UNSPECIFIED));
    int width = view.getMeasuredWidth();
    if (background != null) {
        Rect mTempRect = new Rect();
        background.getPadding(mTempRect);
        width += mTempRect.left + mTempRect.right;
    }
    return width;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!