Android的微调尺寸非常大 [英] Android Spinner Size very large

查看:132
本文介绍了Android的微调尺寸非常大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图得到一个ICS微调喜欢我的应用程序,玩好几个小时,最后我用HoloEverywhere得到这个,它的工作,但我有一个小disign问题,就是微调器没有包装的内容,因为我在XML设置,默认情况下是这样的:

I'm trying to get an ICS spinner like in my app, and playing around for hours, finally I'm using HoloEverywhere to get this, and it's working, but I have a little disign issue, is that the spinner is not wrapping its content as I set in the xml, and by default looks like this :

真的,我用Google搜索这几个小时,而我发现的是,如何调整微调的项目,而不是视图本身,就意味着我要微调调整到所选择的项目大小是这样的:

Really I googled this for hours, and all I found is that how to resize spinner items and not the view itself, means that I want the spinner to be adjusted to the selected item size like this :

下面是我的XML:

<RelativeLayout 
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal" >

<org.holoeverywhere.widget.Spinner
    android:id="@+id/spnCities"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="10dp"
    />

<TextView
    android:id="@+id/tvCities"
    android:layout_width="70dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="10dp"
    android:text="@string/city"
    android:textAppearance="?android:attr/textAppearanceSmall" />

任何帮助将受到欢迎。

感谢。

推荐答案

微调具有最大宽度他的项目,但在大多数家长的宽度(上layout_width = WRAP_CONTENT)。 您可以在org.holoeverywhere.widget封装,覆盖方法measureContentWidth创建CustomSpinner类:

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;
}

这篇关于Android的微调尺寸非常大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆