查找视图的宽度 - onSizeChanged 在我需要它之后调用
基本上我正在构建一个自定义滚动条,其中有一个表格布局。我将表行动态插入到表布局中,然后将文本视图插入到这些行中。我需要知道整个滚动视图的宽度,以便我可以获取该长度并除以每个文本视图的长度。我正在使用 onSizeChanged 方法来获取滚动视图宽度,效果很好。
然而,问题是,我在构造滚动条后立即调用“添加行”方法。这个“添加行”方法显然是在滚动条有机会进入 onSizeChanged 方法之前被调用的,因此在宽度变量仍设置为零时发生“添加行”调用。
有什么办法可以阻止这种交错吗?或者是否有更有效的方法来在构造函数中查找滚动视图的宽度?谢谢!
basically I'm building a custom scroll bar that has a table layout inside it. I'm dynamically inserting table rows into the table layout and then text views into those rows. I need to know how wide the overall scrollview is so I can take that length and divide by each textview's length. i'm using the onSizeChanged method to get the scroll views width, which works fine.
However, the problem is, I call my "add a row" method right after constructing the scroll bar. this "add a row" method is apparently being called before the scroll bar has a chance to enter into the onSizeChanged method, and as such the call to "add a row" happens while the width variable is still set to zero.
Is there a way I can stop this interleaving? Or is there a more efficient way to find the width of the scroll view in the constructor? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能使用
handler
及其postDelayed
方法推迟对addRow
的调用吗?Couldn't you postpone the call of
addRow
using ahandler
and itspostDelayed
method?