How can I manage the height of android spinner items?

大憨熊 提交于 2019-12-04 00:29:43

I've run into this issue myself a while ago, and it turned out that I need to use different layouts for dropdown and display

I have this code:

adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, cGroups,
                new String[] {
                        "name", "_id"
                }, new int[] {
                    android.R.id.text1
                });
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

Yes, the above answer is correct.

It took me forever to find this, because it's wrong in the sdk samples for 2.2 Android. And I had a hard time accepting that.

Here's a snippet from samples/android-12/Spinner/src/com/android/example/spinner/SpinnerActivity.java:

       this.mAdapter = ArrayAdapter.createFromResource(this, R.array.Planets,
                android.R.layout.simple_spinner_dropdown_item);

while it should have android.R.layout.simple_spinner_item there instead and simple_spinner_dropdown_item should only be used for the dropdown items. Otherwise the spinner arrow get streched and it draws dropdown selection circle to the display, too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!