My Spinner's Size Is Too Big

My huge counter: http://i.stack.imgur.com/zNxdX.jpg

As you can see in the picture, my counter is 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?

+4
source share
2 answers

Your spinner looks like this because you used the wrong layout when you created the ArrayAdapter. Change it like this:

 ... = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spinnerArray); 

The layout android.R.layout.simple_dropdown_item_1line used for the counter elements in the drop-down mode. Instead, you should pass the layout to android.R.layout.simple_spinner_item . Then the spinner should look normal.

If you want to change the layout for the drop-down list, you can set it using the setDropDownViewResource () method of the adapter class.

+19
source

Make the text smaller for the spinner elements and the counter will be smaller. If you use very large text for items, the counter must be large to display the selected item.

+2
source

Source: https://habr.com/ru/post/1339985/


All Articles