Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java for Android
  • Android Studio
  • Android Kotlin
  • Kotlin
  • Flutter
  • Dart
  • Android Project
  • Android Interview
Open In App
Next Article:
Difference Between View and ViewGroup in Android
Next article icon

Difference Between View and ViewGroup in Android

Last Updated : 17 Mar, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

In Android Layout is used to describe the user interface for an app or activity, and it stores the UI elements that will be visible to the user. An android app's user interface is made up of a series of View and ViewGroup elements. In most cases, android apps will have one or more operations, each of which is a single screen of the app. Multiple UI components will be present in the operations, and those UI components will be instances of the View and ViewGroup subclasses. Generally, the android apps will contain one or more activities and each activity is one screen of the app. The activities will contain multiple UI components and those UI components are the instances of View and ViewGroup subclasses. In Android apps, the two very central classes are the Android View class and ViewGroup class. One or more tasks can be found in an Android app. A screen in an Android operation is identical to the windows in a desktop application. GUI components may be used in an operation. View or ViewGroup subclasses are used to build the GUI elements. 

View is a basic building block of UI (User Interface) in android. A view is a small rectangular box that responds to user inputs. Eg: EditText, Button, CheckBox, etc. ViewGroup is an invisible container of other views (child views) and other ViewGroup. Eg: LinearLayout is a ViewGroup that can contain other views in it. ViewGroup is a special kind of view that is extended from View as its base class. ViewGroup is the base class for layouts. As the name states View is singular and the group of Views is the ViewGroup. In simple terms, a view is a user interface feature that we interact with when we use an app, such as a button, editing text and images, and so on. Android.view has a child class called View. Observe While the View group is the container that houses all of these views as well as many other ViewGroup such as linear or Frame Layout. For example, if we design and use the LinearLayout as the root feature, our main layout would be the LinearLayout. Within it, we can add another view category (i.e. another LinearLayout) and several other views such as buttons or TextViews.

View

The View class is the base class or we can say that it is the superclass for all the GUI components in android. For example, the EditText class is used to accept the input from users in android apps, which is a subclass of View, and another example of the TextView class which is used to display text labels in Android apps is also a subclass of View. 

Or the other definition,

View refer to the android.view.View class, which is the base class of all UI classes. android.view.View class is the root of the UI class hierarchy. So from an object point of view, all UI objects are View objects. Following are some of the common View subclasses that will be used in android applications.

  • TextView
  • EditText
  • ImageView
  • RadioButton
  • Button
  • ImageButton
  • CheckBox
  • DatePicker
  • Spinner
  • ProgressBar and etc.

These are some of the view subclass available in android. 

ViewGroup

The ViewGroup class is a subclass of the View class. And also it will act as a base class for layouts and layouts parameters.  The ViewGroup will provide an invisible container to hold other Views or ViewGroups and to define the layout properties. For example, Linear Layout is the ViewGroup that contains UI controls like Button, TextView, etc., and other layouts also. ViewGroup Refer to the android.view.ViewGroup class, which is the base class of some special UI classes that can contain other View objects as children. Since ViewGroup objects are also View objects, multiple ViewGroup objects and View objects can be organized into an object tree to build a complex UI structure. Following are the commonly used ViewGroup subclasses used in android applications.

  • FrameLayout
  • WebView
  • ListView
  • GridView
  • LinearLayout
  • RelativeLayout
  • TableLayout and many more.

The ViewGroup subclasses listed above group View instances together and takes care of their layout. For instance, the LinearLayout will render the components after each other either horizontally or vertically.

View and ViewGroup in Android

Difference Table

                                          View                                                      ViewGroup
View is a simple rectangle box that responds to the user's actions.ViewGroup is the invisible container. It holds View and ViewGroup
View is the SuperClass of All component like TextView, EditText, ListView, etcViewGroup is a collection of Views(TextView, EditText, ListView, etc..), somewhat like a container.
A View object is a component of the user interface (UI) like a button or a text box, and it's also called a widget.A ViewGroup object is a layout, that is, a container of other ViewGroup objects (layouts) and View objects (widgets)
Examples are EditText, Button, CheckBox, etc.For example, LinearLayout is the ViewGroup that contains Button(View), and other Layouts also.
View refers to the android.view.View classViewGroup refers to the android.view.ViewGroup class
android.view.View which is the base class of all UI classes.ViewGroup is the base class for Layouts.

So, these all are the basic key difference between the View class and Viewgroup class in Android.


Next Article
Difference Between View and ViewGroup in Android

K

kaaruni1124
Improve
Article Tags :
  • Difference Between
  • Android

Similar Reads

    Android - Difference Between RecyclerView and ListView
    In Android View is a basic building block of UI (User Interface). A view is a small rectangular box that responds to user inputs. RecyclerView and ListView are the two major Views in Android. So in this article, we are going to see the major differences between these two views. RecyclerView Recycler
    3 min read
    Difference Between LinearLayout and RelativeLayout in Android
    In Android, LinearLayout and RelativeLayout are view groups used for arranging UI elements , but they are have few differences in their behavior and use cases.Difference Between LinearLayout and RelativeLayoutLinearLayout RelativeLayout We can adjust views and widgets linearly i.e. Horizontally and
    3 min read
    Difference between Android Toast and SnackBar
    1. Toast : It is an Android UI component that is used to show message or notification that does not require any user action. It is independent to the activity in which it is being shown and disappears automatically after the set duration. 2. SnackBar : It is Android material design UI component. It
    1 min read
    What is the Difference Between “px”, “dip”, “dp” and “sp” in Android?
    Defining dimensions in Android Development is a crucial part as plays a huge role in creating user interfaces that are both visually appealing and adaptive across all screen sizes and resolutions. Android provides us several measurement units such as px, dip, dp, sp, etc that helps in maintaining co
    5 min read
    Difference Between MVC and MVP Architecture Pattern in Android
    Developing an android application by applying a software architecture pattern is always preferred by the developers. An architecture pattern gives modularity to the project files and assures that all the codes get covered in Unit testing. It makes the task easy for developers to maintain the softwar
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences