A ViewGroup is a (subclass of) View because it can serve as a view in important ways:
- It can be an element in a layout XML file
- It can be displayed on the screen (by displaying its child views, its own background color, etc.)
- It gets inflated along with the rest of the view hierarchy
- It can serve as an activity's content view (via
setContentView())
So it really is a View.
I agree that the classname ViewGroup is a bit confusing, because it sounds like it's a group, not a view. Calling it ViewGroupView might have been more logical, if unwieldy.
Why did folks at Android define this relationship as Inheritance instead of composition? As the ViewGroup contains Views shouldn't it be composition?
In a case like this, inheritance and composition are not mutually exclusive. A ViewGroup is a View (inheritance) and a ViewGroup can contain Views (composition).