ProgressBar.java 的 Android 源代码没有任何意义
我正在查看 Android SDK 中的 ProgressBar.java 源代码。在 android.widget.ProgressBar 的第 191 行,它指出:
mMinHeight = a.getDimensionPixelSize(R.styleable.ProgressBar_minHeight, mMinHeight));
为什么它在初始化时同时在参数列表中使用 mMinHeight ?有人可以阐明这一点吗?完整的源代码可以位于 grepcode。
I am reviewing the ProgressBar.java sourcecode from Android's SDK. On line 191 of android.widget.ProgressBar it states:
mMinHeight = a.getDimensionPixelSize(R.styleable.ProgressBar_minHeight, mMinHeight));
Why is it using mMinHeight in the parameter list at the same time as it is initializing it?? Can someone shed light on this? The full sourcecode can be located here at grepcode.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看到第 171 行调用
initProgressBar
的地方了吗?该方法将 mMinHeight 初始化为值 24。然后对 getDimensionPixelSize 的调用将其用作默认值。See on line 171 where it calls
initProgressBar
? That method initializes mMinHeight to the value of 24. Then the call togetDimensionPixelSize
uses that as the default value.第二个参数只是一个默认值,如果
getDimensionPixelSize
无法找到请求的值,则应返回该默认值。传递您尝试设置为默认值的变量是很常见的(虽然有点奇怪)。实际上,这段代码表示“如果有该值,则设置该值;如果没有,则将变量保留原样”。The second parameter is just a default value that should be returned if
getDimensionPixelSize
is not able to find the requested value. It's common (if slightly weird) to pass in the variable you're attempting to set as the default value. Effectively, this code says "set this value if you have it, or just leave the variable as it is if you don't".