我正在尝试获得像我的应用程序中那样的 ICS 旋转器,并玩了几个小时,最后我使用 HoloEverywhere 来获得它,并且它正在工作,但我有一个设计问题,即旋转器没有包装其我在 xml 中设置的内容,默认情况下如下所示:
实际上,我在谷歌上搜索了几个小时,我发现的是如何调整微调器项目的大小而不是视图本身,这意味着我希望将微调器调整为所选项目的大小,如下所示:
这是我的 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" />
</RelativeLayout>
Spinner 的项目具有最大宽度,但最多为父宽度(在布局宽度 = 包装内容上)。
您可以在 org.holoeverywhere.widget 包中创建 CustomSpinner 类并覆盖方法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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)