Android:减少微调器下拉框的宽度

发布于 2024-12-08 21:34:42 字数 324 浏览 0 评论 0原文

我已经查看了有关此主题的大多数问题,但似乎没有明确的答案。我在表视图的不同行中有三个微调器。使用权重属性,表格中的单元格以及旋转器和文本视图都具有相同的宽度。

但是,当单击微调器时,下拉列表会以全宽显示并覆盖整个表格。必须有一种方法来限制列表的宽度。毕竟它最多只能容纳 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光倒影 2024-12-15 21:34:42

但是,当单击微调器时,下拉列表会以全宽显示并覆盖整个表格。

那是因为它实际上是一个弹出对话框。

必须有一种方法来限制列表的宽度。

这很困难,因为您不是创建对话框的人。考虑到 Spinner 的编写方式,我什至不知道如何通过使用自己的子类扩展 Spinner 来实现此目的。您可能必须克隆 Spinner 源代码,将其移至另一个包(或类名),然后更改 performClick() 以更改 AlertDialog 的大小 使用 如何控制Android 中默认警报对话框的宽度和高度?

并且,请记住,Spinner 的行为在 Honeycomb 上显着不同,并且它在 Ice Cream Sandwich 上的表现还有待观察。我们没有 Honeycomb 源代码,因此我的克隆解决方案将在较新的设备上给您带来问题。

我看到了关于 R.attr.dropDownWidth 的注释,看起来似乎可能有帮助,但我不知道如何实现这个方法,更不用说它是否真的有效。

它不是一个方法,而是一个可以在样式中设置的属性。但是,根据源代码,这似乎仅用于 AutoCompleteTextView 的下拉列表。

However, when a spinner is clicked, the drop-down list appears at full width and covers the whole table.

That is because it is really a pop-up dialog.

There must be a way of restricting the width of the list.

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 the Spinner source code, move it to another package (or class name), and alter performClick() to change the size of the AlertDialog 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.

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文