Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a View and widget in Android?

Tags:

android

What is the difference between a View and widget in Android?

like image 644
dataonly Avatar asked Mar 02 '11 14:03

dataonly


People also ask

What is a widget in Android?

A widget is a small gadget or control of your android application placed on the home screen. Widgets can be very handy as they allow you to put your favourite applications on your home screen in order to quickly access them.

What is the view in Android?

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.

What is the purpose of a widget?

A widget is an element of a graphical user interface (GUI) that displays information or provides a specific way for a user to interact with the operating system or an application.

What are the different types of widgets in Android?

There are, in general, four types of widgets: information widgets, collection widgets, control widgets, and hybrid widgets.


2 Answers

As is stated in the View class docs:

This 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.).

The ViewGroup subclass is the base class for layouts, which are invisible containers that hold other Views (or other ViewGroups) and define their layout properties.

Therefore a View is a base class for UI elements and a Widget is loosely defined as any ready to use View.


Let's emphasize these concepts a little more.

View

A View is a base class for all UI elements. It, therefore, covers many different classes and concepts, including widgets, ViewGroups and layouts. There is a root View attached to a Window instance which forms the basis of the View hierarchy. In general, the word View is usually used to describe UI elements in general, or to refer to abstract or base UI classes such as ViewGroups.

Widget

There are various definitions for this term, but most refer to a "ready to use" UI element, be it a Button, ImageView, EditText, etc. Note that some people consider widgets to be UI elements that are complete (not abstract) and are not containers (such as ViewGroups (layouts/ListViews)). It's also worth noting that "widget" is a package name (android.widget) where the docs mention the following:

The widget package contains (mostly visual) UI elements to use on your Application screen.

Therefore, it is reasonable to consider non-visual UI elements to also be widgets, as well as any class defined under the widget package. See here for a full list of classes in the widget package: http://developer.android.com/reference/android/widget/package-summary.html


App Widget

Not to be confused with a UI element widget, an App Widget is a remote View hierarchy which is most commonly displayed on the user's home screen. As defined by the docs:

App Widgets are miniature application views that can be embedded in other applications (such as the Home screen) and receive periodic updates. These views are referred to as Widgets in the user interface, and you can publish one with an App Widget provider. An application component that is able to hold other App Widgets is called an App Widget host.

ViewGroup

A ViewGroup is a subclass of View and provides the ability to parent and position child Views, such as in the case of Layouts.

Layout/View Containers

Much as with Widgets, there is no Layout base class, therefore it could be loosely defined as any class which extends ViewGroup and provides the ability to define the positioning of child Views within it. Usually, only ViewGroup subclasses which are appended with the word "Layout" (as in LinearLayout, RelativeLayout) are referred to as "layouts", other classes extending ViewGroup are usually just referred to as "view containers".

Finally, I'd like to suggest that whenever you mention Views, widgets or any other important term, to make it clear your intended definition so that people can better understand what you're referring to.


Further Reading

  • What is the difference between Views and widgets?
like image 130
TheIT Avatar answered Sep 28 '22 00:09

TheIT


A Widget is a View. A Layout is a ViewGroup. To create a widget, you extend a View.

like image 38
JAL Avatar answered Sep 28 '22 01:09

JAL