Android:业余程序员关于示例“Snake”的问题
谢谢如果有人能回答这个(也许?)荒谬的问题:
为什么 SnakeView.java 中的 “public SnakeView” 定义两次 (第一次直接一次!),第二次添加 arg "int defStyle" ?
(这些“公众”两次调用“initSnakeView”...)
为什么这是必要的 - 是什么优势?
非常感谢您启发!
Thanks if anybody will answer this (maybe?) ridiculous question:
Why is a "public SnakeView" in SnakeView.java defined TWICE (once directly after the first time!), adding the second time an arg "int defStyle" ?
(Both times these "publics" call "initSnakeView"...)
Why is this necessary - what is the advantage?
THANK YOU very much for an enlightenment !!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SnakeView
类是TileView
的子类,而TileView
又是View
的子类。这两个 public SnakeView 定义实现了每个 View 都有的两个构造函数。第一个在从代码创建
View
时调用,第二个在从布局 xml 文件扩充时调用。请参阅此处。The
SnakeView
class sublassesTileView
, which in turn subclassesView
.Those two
public SnakeView
definitions implement the two constructors that everyView
has. The first one is called when creating aView
from code, the second one is called when it is inflated from a layout xml file. See here.这些是“构造函数”——一种特殊的函数,在创建 SnakeView 对象时调用。构造函数有机会设置对象的初始状态。一个类可以有许多不同的构造函数和不同的对象集;每个人都根据给定的输入来设置对象。没有参数的构造函数是“默认”构造函数,它在没有任何输入的情况下使用默认值。
Those are "constructors" -- a special kind of function that is called when a SnakeView object it being created. A constructor has the opportunity to set up the initial state of the object. A class can have many different constructors with different sets of objects; each one sets up the object based on whatever inputs are given. The one with no arguments is a "default" constructor, which uses default values in the absence of any input.