Difference between View and ViewGroup in Android

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

+77
android view viewgroup
Dec 08 '14 at 6:24
source share
11 answers

View

  • View objects are the main building blocks of user interface elements (UI) in Android.
  • View is a simple rectangle that responds to user actions.
  • Examples are EditText , Button , CheckBox , etc.
  • View belongs to the class android.view.View , which is the base class of all user interface classes.

ViewGroup

  • ViewGroup is an invisible container. It contains View and ViewGroup
  • For example, LinearLayout is a ViewGroup that contains a button (view) and other layouts.
  • ViewGroup is the base class for layouts.
+118
Jan 08 '16 at 12:09 on
source share

Below is the answer . Do not consider it too complicated.

enter image description here

+49
Aug 28 '15 at 10:48
source share
  1. ViewGroup is a special view that may contain other views (called ViewGroup ). A view group is the base class for layout and view containers. This class also defines the ViewGroup.LayoutParams class which serves as the base class for layout options.

    View class is the main building block for user interface components. The view occupies a rectangular area on the screen and is responsible for drawing and handling events. A view is the base class for widgets that are used to create interactive user interface components (buttons, text fields, etc.).

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

Link

+23
Dec 08 '14 at 6:32
source share

View is the main building block of the UI (User Interface) in android. The view is a small rectangular block that responds to user inputs. For example: EditText , Button , CheckBox , etc.

ViewGroup - an invisible container of other views (child views) and other groups of views. For example: LinearLayout is a group of views that can contain other views.

ViewGroup is a special kind of view that expands from a view as its base class. ViewGroup is the base class for layouts.

as state names. The view is the only one, and the group of views is the ViewGroup .

Additional information: http://www.herongyang.com/Android/View-ViewGroup-Layout-and-Widget.html

+13
Dec 08 '14 at 6:32
source share

ViewGroup itself is a View that works like a container for other views. It extends the functionality of the View class to provide efficient ways to host child views.

For example, LinearLayout is a ViewGroup that allows you to determine the orientation in which you want to create child views, all you need to do, and LinearLayout will take care of the rest.

+3
Dec 08 '14 at 6:35
source share

A viewgroup inherits view properties and does more with other views and a view group.

See Android API: http://developer.android.com/reference/android/view/ViewGroup.html

+2
Dec 08 '14 at 6:28
source share

View:

  • Refer to the android.view.View class, which is the base class for all user interface classes. android.view.View class is the root of the user interface class hierarchy. Thus, from an object point of view, all user interface objects are View objects.

ViewGroup:

  • Refer to the android.view.ViewGroup class, which is the base class of some special user interface classes that can contain other View objects as children. Since ViewGroup objects ViewGroup also View objects, several ViewGroup objects and View objects in the object tree can be organized to create a complex user interface structure.
+1
Nov 04 '16 at 6:04
source share

in ViewGroup you can add another View as a child. ViewGroup is the base class for layouts and views.

0
Dec 08 '14 at 6:26
source share

View is the SuperClass class for everyone, e.g. TextView, EditText, ListView, etc. and ViewGroup is an assembly of views (TextView, EditText, ListView, etc..) , somewhat similar to a container.

0
Dec 08 '14 at 6:31
source share

ViewGroup describes the layout of views in its group. The two main examples of ViewGroups are LinearLayout and RelativeLayout. By breaking LinearLayout even further, you can use either Vertical LinearLayout or Horizontal LinearLayout. If you select Vertical LinearLayout, your views will stack vertically on your screen. The two main examples of views are TextView and Button. That way, if you have a ViewGroup Vertical LinearLayout, your views (like TextViews and buttons) will be positioned vertically down the screen.

When other posters show nested ViewGroups, they mean, for example, that one of the lines in my Vertical LinearLayout can actually represent several elements horizontally at the lower level. In this case, I would use Horizontal LinearLayout as one of the descendants of my top level Vertical LinearLayout.

An example of nested ViewGroups:
Parent ViewGroup = Vertical LinearLayout

Row1: TextView1
Row2: Button1
Row3: Image TextView2 Button2 <- Horizontal linear, nested in vertical linear
Row4: TextView3
Row5: Button3

0
Feb 25 '18 at 15:18
source share

A View object is a component of a user interface (for example, a button or text field), which is also called a widget.

A ViewGroup object is a layout, that is, a container of other ViewGroup objects (layouts) and View objects (widgets). You can have a layout inside another layout. It's called a nested layout, but it can increase the time it takes to draw the user interface.

The user interface for the application is built using a hierarchy of ViewGroup and View objects. In Android Studio, you can use the component tree window to visualize this hierarchy.

You can use the layout editor in Android Studio to drag and drop View objects (widgets) into the layout. This makes layout easy.

0
Jul 12 '19 at 14:48
source share



All Articles