更改微调器DropDown宽度

我需要调整这个部分的大小,以充分显示。 我怎样才能做到这一点?

示例图像

我的适配器:

String[] navigations = getResources().getStringArray(R.array.actionBar); ArrayAdapter<String> adapter = new ArrayAdapter<String>( getBaseContext(), R.layout.custom_spinner_title_bar, android.R.id.text1, navigations); adapter.setDropDownViewResource(R.layout.custom_spinner_title_bar); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); actionBar.setListNavigationCallbacks(adapter, navigationListener); 

custom_spinner_title_bar.xml:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/RelativeLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="fill_horizontal" android:orientation="vertical" > <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:padding="5dip" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#FFFFFF" /> </RelativeLayout> 

Solutions Collecting From Web of "更改微调器DropDown宽度"

在Spinner标签的xml文件中添加属性

机器人:dropDownWidth = “150dp”

你需要做的是使用一个自定义适配器的下拉,而不是默认的,你可以设置每个“行”的“minimumWidth”为任何你想要的:

 private class myCustomAdapter extends ArrayAdapter{ private List<String> _navigations; private int _resource; private int _textViewResourceId; public myCustomAdapter (Context context, int resource, int textViewResourceId, List<String> objects) { super(context, resource, textViewResourceId, objects); _navigations = objects; _resource = resrouce; _textViewResourceId = textViewResourceId; } @Override public View getDropDownView(int position, View convertView, ViewGroup parent){ View row; LayoutInflater inflater=getLayoutInflater(); row = inflater.inflate(_resource, null); TextView _textView = row.findViewById(_textViewResourceId); _textView.setText(_navigations.get(position)); Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); int _width = size.x; row.setMinimumWidth = _width; return row; } } 

你当然可以用“minimumWidth”来玩任何你想要的; 在这个例子中,它只是设置为与屏幕宽度相匹配(尽pipe更聪明的方法是测量应用程序的容器框架并将其与之匹配)。

然后设置适配器:

 myCustomAdapter adapter = new myCustomAdapter(getBaseContext(), R.layout.custom_spinner_title_bar,android.R.id.text1, navigations);