aspartame aspartame - 2 months ago 21
Android Question

Manually set width of spinner dropdown list in android

Is it possible to set the width of a spinner dropdown list in code? I have a spinner populated with integers, and it does not look good with the list expanding to full width. Can I set the width to wrap the content somehow?

Spinner hSpinner = (Spinner) timerView.findViewById(;
ArrayList<Integer> hList = new ArrayList<Integer>(21);

for (int i = 0; i <= 20; i++) { hList.add(i); }

ArrayAdapter hAdapter = new ArrayAdapter(RemindMe.this, android.R.layout.simple_spinner_item, hList);





You can change the width of anything in code by adjusting its LayoutParams. The details of that varies by container (LinearLayout vs. RelativeLayout vs. ...).

However, I'm confused why you want to change the width "in code". Why not just set the width to be wrap_content in the layout XML?