Difference between View and ViewGroup in Android
Solution 1
View
-
View
objects are the basic building blocks of User Interface(UI) elements in Android. -
View
is a simple rectangle box which responds to the user's actions. - Examples are
EditText
,Button
,CheckBox
etc.. -
View
refers to theandroid.view.View
class, which is the base class of all UI classes.
ViewGroup
-
ViewGroup
is the invisible container. It holdsView
andViewGroup
- For example,
LinearLayout
is theViewGroup
that contains Button(View), and other Layouts also. -
ViewGroup
is the base class for Layouts.
Solution 2
Below image is the answer. Don't take it too complex.
Solution 3
-
A
ViewGroup
is a special view that can contain other views (called children.) The view group is the base class for layouts and views containers. This class also defines theViewGroup.LayoutParams
class which serves as the base class for layouts parameters.View
class represents the basic building block for user interface components. A View occupies a rectangular area on the screen and is responsible for drawing and event handling. View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.). - Example : ViewGroup (LinearLayout), View (TextView)
Solution 4
View
is a basic building block of UI
(User Interface) in android. A view is a small rectangular box which responds to user inputs. Eg: EditText
, Button
, CheckBox
, etc..
ViewGroup
is a invisible container of other views (child views) and other viewgroups. Eg: LinearLayout
is a viewgroup which can contain other views in it.
ViewGroup
is a special kind of view which is extended from View as its base class. ViewGroup
is the base class for layouts.
as name states View is singular and the group of Views is the ViewGroup
.
more info: http://www.herongyang.com/Android/View-ViewGroup-Layout-and-Widget.html
Solution 5
ViewGroup
is itself a View
that works as a container for other views. It extends the functionality of View
class in order to provide efficient ways to layout the child views.
For example, LinearLayout
is a ViewGroup
that lets you define the orientation in which you want child views to be laid, that's all you need to do and LinearLayout
will take care of the rest.
Admin
Updated on June 29, 2020Comments
-
Admin almost 4 years
What is the difference between a
View
and aViewGroup
in Android programming? -
ivanleoncz over 7 yearsStraight to the point. The image explains it in a very pragmatic way, which is good, but the definition of the above answer seems also necessary in order to add something important to the answer as a whole.
-
Lv99Zubat about 7 yearsalso I think worth noting, ViewGroup is a subclass of View
-
sv Math Tutor about 6 yearsExample of Nested ViewGroups:
-
Shivanshu about 5 yearsSo, If ViewGroup is a subclass of View means View is base class for Layouts not ViewGroup?
-
horcrux over 4 years@Shivanshu It depends on what you mean by "base class". The class
View
in turn extendsObject
, so would you say thatObject
is base class for layouts?