为什么我不能从 android.view 继承受保护的字段?
我试图覆盖 offsetTopAndBottom(int offset)
方法,它是一个 View
类方法。 但是,当我尝试访问 mTop
或 mBottom
字段时,即使它们在 View
类中受到保护
,我收到一个错误。
有谁知道为什么我会遇到这种访问问题?
例如:
CustomView extend android.view.View{
someOverridenMethod()
{
mTop = 10 //error, mTop no resolved as a type
}
}
I'm trying to override the offsetTopAndBottom(int offset)
method which is a View
class method.
But when I try to access the mTop
or mBottom
fields, even though they are protected
in the View
class, I get an error.
Does anyone know why I would have this kind of access problem ?
For example:
CustomView extend android.view.View{
someOverridenMethod()
{
mTop = 10 //error, mTop no resolved as a type
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所有
m{variables}
均不可访问。我一辈子都不记得为什么,与m{variables}
不属于公共 API 的一部分有关。我也遇到了类似的问题,经过几天的搜索,我几乎发现这是不可能的。
我相信你可以尝试调用
View.layout(int left, int top, int right, int Bottom)
;这将最终设置
mTop
值,此时您可以调用getTop()
。然而,有一种方法很疯狂,您会发现许多其他方法将被调用。所以这是否真的对你有帮助还有待观察。All
m{variables}
are not accessible. For the life of me I can't remember why, something to do withm{variables}
not being part of the public API.I had a similar problem and after days of searching, I pretty much found it to be impossible.
I believe you can try calling
View.layout(int left, int top, int right, int bottom)
;this will ultimately set the
mTop
value, at which point you can callgetTop()
. However there is a method to the madness and you will find that a number of other methods will be called as a result. So whether this actually helps you or not is well...to be seen.根据 View javadoc 没有名为 的成员或方法mTop。
According to the View javadoc there is no member or method called mTop.