Android:减少微调器下拉框的宽度
我已经查看了有关此主题的大多数问题,但似乎没有明确的答案。我在表视图的不同行中有三个微调器。使用权重属性,表格中的单元格以及旋转器和文本视图都具有相同的宽度。
但是,当单击微调器时,下拉列表会以全宽显示并覆盖整个表格。必须有一种方法来限制列表的宽度。毕竟它最多只能容纳 4 位数字。
我看到过关于 R.attr.dropDownWidth 的注释,看起来好像可能有帮助,但我不知道如何实现这个方法,更不用说它是否真的有效了。
任何有关此或另一种将下拉宽度限制为大约 100 个倾角的方法的帮助都将非常感激 - 特别是如果包含示例代码。
谢谢,
艾伦...
I have looked at most of the questions on this subject and there does not seem to be a definitive answer. I have three spinners in different rows of a table view. Using the weight attribute, the cells in the table and,consequently, the spinners and text views all have the same width.
However, when a spinner is clicked, the drop-down list appears at full width and covers the whole table. There must be a way of restricting the width of the list. It only holds a number with a maximum of 4 digits after all.
I have seen a note on R.attr.dropDownWidth which looks as though it may help but I have no idea how to implement this method, let alone if it will actually work.
Any help on this or another method that will restrict the width of the drop-down to about 100 dip will be really appreciated - especially if sample code is included.
Thanks,
Alan ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那是因为它实际上是一个弹出对话框。
这很困难,因为您不是创建对话框的人。考虑到
Spinner
的编写方式,我什至不知道如何通过使用自己的子类扩展 Spinner 来实现此目的。您可能必须克隆Spinner
源代码,将其移至另一个包(或类名),然后更改performClick()
以更改AlertDialog 的大小
使用 如何控制Android 中默认警报对话框的宽度和高度?。并且,请记住,
Spinner
的行为在 Honeycomb 上显着不同,并且它在 Ice Cream Sandwich 上的表现还有待观察。我们没有 Honeycomb 源代码,因此我的克隆解决方案将在较新的设备上给您带来问题。它不是一个方法,而是一个可以在样式中设置的属性。但是,根据源代码,这似乎仅用于
AutoCompleteTextView
的下拉列表。That is because it is really a pop-up dialog.
This is difficult, as you are not the one creating the dialog. I do not even see how you could accomplish this by extending Spinner with your own subclass, given the way
Spinner
is written. You might have to clone theSpinner
source code, move it to another package (or class name), and alterperformClick()
to change the size of theAlertDialog
using the techniques outlined in How to control the width and height of the default Alert Dialog in Android?.And, bear in mind that the behavior of
Spinner
is significantly different on Honeycomb, and it remains to be seen how it looks on Ice Cream Sandwich. We do not have the Honeycomb source code, so my clone-the-class solution is going to give you problems on newer devices.It is not a method, but rather an attribute you could set in a style. However, based on the source code, it appears that this is only used for
AutoCompleteTextView
's drop-down.