Difference between View and ViewGroup in Android

2019-01-10 06:37发布

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

9条回答
手持菜刀,她持情操
2楼-- · 2019-01-10 07:10
  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

查看更多
ら.Afraid
3楼-- · 2019-01-10 07:10

View is the SuperClass of All component like TextView, EditText, ListView, etc.. while ViewGroup is Collection of Views(TextView, EditText, ListView, etc..), somewhat like container.

查看更多
家丑人穷心不美
4楼-- · 2019-01-10 07:16

Viewgroup inherits properties of views and does more with other views and viewgroup.

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

查看更多
地球回转人心会变
5楼-- · 2019-01-10 07:18

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.
查看更多
ゆ 、 Hurt°
6楼-- · 2019-01-10 07:18

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

enter image description here

查看更多
Anthone
7楼-- · 2019-01-10 07:19

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

查看更多
登录 后发表回答