My huge spinner: http://i.stack.imgur.com/zNxdX.jpg
As you can see in the picture, my spinner is way too huge. I can't seem to find the problem. Here is the code:
RelativeLayout.LayoutParams lpSpinner = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
spTest = new Spinner(this);
String[] spinnerArray={"1","2","3","4","5","6","7","8","9","10"};
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, spinnerArray);
spTest.setAdapter(spinnerArrayAdapter);
spTest.setId(4);
lpSpinner.addRule(RelativeLayout.ALIGN_RIGHT, lblText.getId());
relative.addView(spTest, lpSpinner);
what am i doing wrong?
Your spinner lookes like this because you used the wrong layout when you created the ArrayAdapter. Change it to this:
... = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,
spinnerArray);
The android.R.layout.simple_dropdown_item_1line
layout is used for the items of the spinner in drop down mode. You have to pass the android.R.layout.simple_spinner_item
layout instead. Then the spinner should look normal now.
If you want to change the layout for the drop down view then you can set it using the setDropDownViewResource() method of the Adapter class.
Make the text smaller for the spinner items, and the spinner will be rendered smaller. If you use very large text for items, the spinner needs to be large to display the selected item.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With