Difference between View and ViewGroup in Android

109,128

Solution 1

View

  1. View objects are the basic building blocks of User Interface(UI) elements in Android.
  2. View is a simple rectangle box which responds to the user's actions.
  3. Examples are EditText, Button, CheckBox etc..
  4. View refers to the android.view.View class, which is the base class of all UI classes.

ViewGroup

  1. ViewGroup is the invisible container. It holds View and ViewGroup
  2. For example, LinearLayout is the ViewGroup that contains Button(View), and other Layouts also.
  3. ViewGroup is the base class for Layouts.

Solution 2

Below image is the answer. Don't take it too complex.

enter image description here

Solution 3

  1. 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 the ViewGroup.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.).

  2. Example : ViewGroup (LinearLayout), View (TextView)

Reference

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.

Share:
109,128
Admin
Author by

Admin

Updated on June 29, 2020

Comments

  • Admin
    Admin almost 4 years

    What is the difference between a View and a ViewGroup in Android programming?

  • ivanleoncz
    ivanleoncz over 7 years
    Straight 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
    Lv99Zubat about 7 years
    also I think worth noting, ViewGroup is a subclass of View
  • sv Math Tutor
    sv Math Tutor about 6 years
    Example of Nested ViewGroups:
  • Shivanshu
    Shivanshu about 5 years
    So, If ViewGroup is a subclass of View means View is base class for Layouts not ViewGroup?
  • horcrux
    horcrux over 4 years
    @Shivanshu It depends on what you mean by "base class". The class View in turn extends Object, so would you say that Object is base class for layouts?