Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size of my Spinner too big

Tags:

java

android

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?

like image 439
Alex Avatar asked Feb 16 '11 12:02

Alex


2 Answers

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.

like image 196
Flo Avatar answered Sep 30 '22 06:09

Flo


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.

like image 28
Ollie C Avatar answered Sep 30 '22 05:09

Ollie C