如何管理Android Spinner项目的高度? [英] How to manage the height of android spinner items?

查看:909
本文介绍了如何管理Android Spinner项目的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用ArrayAdapter填充字符串列表的android旋转器,它运行良好,但是由于显示旋转器的方式,我遇到了列表项的显示高度问题.

I have an android spinner that's populated by a list of strings using an ArrayAdapter and it operates fine, however because of the way the spinner is displayed I'm running into a display height problem with the list items.

乍看之下,似乎ArrayAdapter可以使用单个布局来显示选项,这会导致我遇到的问题.当在微调器中显示当前项目时(当用户未从列表中选择新项目时),微调器将填充文本,以便微调器具有合理的单击大小.但是,当用户点击它并显示列表以选择一个新项目时,显示的列表项目在高度上就太小了.如果我使用一种以合理的高度显示列表项目的项目布局,那么微调框本身由于其自身对列表项目的填充而变得异常庞大.

At first glance, it would seem that the ArrayAdapter can use a single layout for displaying options which leads to the problem I'm having. When displaying the current item in the spinner (when the user is not selecting a new item from the list) the spinner pads the text so that the spinner is a reasonable size for clicking on. However, when the user taps on it and brings up the list to select a new item, the list items presented are way too small height-wise. If I use an item layout that presents the list items at a reasonable height, then the spinner itself becomes exorbitantly huge due to its own padding of the list item.

关于如何管理这两个项目显示模式的高度的任何想法,以便它们有效地以相同的高度值显示,而不是微调器高度大于列表项目的显示高度?

Any ideas on how I can manage the height of these two item display modes so that effectively they display with the same height value instead of the spinner height being larger than the list item display height?

推荐答案

前一段时间我自己遇到了这个问题,事实证明我需要对下拉菜单和显示使用不同的布局

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

我有此代码:

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);

这篇关于如何管理Android Spinner项目的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆