Android设备上查看和ViewGroup中设备、Android、ViewGroup

2023-09-08 10:24:19 作者:_______萌你妹

在Android的的ViewGroup 查看继承。 A 的ViewGroup 是持有查看

In Android ViewGroup inherits from View. A ViewGroup is a container which holds Views.

ViewGroup (LinearLayout)
View (TextView)

为什么在Android的乡亲定义这种关系为继承,而不是组成。由于的ViewGroup 包含查看不是它应该是组成?

Why did folks at Android defined this relationship as Inheritance instead of composition. As the ViewGroup contains Views shouldn't it be composition ?

推荐答案

我想你上了挂在措辞。

A的ViewGroup有每一点多少理由从查看继承为TextView的和ImageView的或...更重要的是......一个滚动型或SurfaceView (后两者都包含的东西)。

A "ViewGroup" has every bit as much reason to inherit from a "View" as a "TextView", and "ImageView" or ... more to the point ... a "ScrollView" or a "SurfaceView" (the latter two both "contain things").

或许,查看并不一定条件的最佳选择......但是类层次结构,使完整意义。不管是什么它的子类被命名为:)

Perhaps "View" wasn't necessarily the best choice of terms ... but the class heirarchy makes complete sense. Regardless of what it's subclasses are named :)

恕我直言...