Reputation: 1185
in my app I am using a Spinner to show a list of items. I am changing the width of the spinner in my code dynamically, but the width of the dropdown is also changing along with the spinner.
I want to fix the width of the dropdown list but not for spinner. So how can I do this without using xml?
Upvotes: 1
Views: 1768
Reputation: 3316
Set dropdown width in xml file of spinner using the tag
android:dropDownWidth="@dimen/desired_width"
Explaination :
mDropDownWidth = pa.getLayoutDimension(R.styleable.Spinner_dropDownWidth,
ViewGroup.LayoutParams.WRAP_CONTENT);
this field is used for dropdown width when spinner item is initialized in Spinner class
for programatically changing spinner dropdown width above api level 16, use
mSpinner.setDropDownWidth(size_in_pixel);
Upvotes: 2