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

后端 未结 9 1766
轮回少年
轮回少年 2020-12-24 11:39

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

相关标签:
9条回答
  • 2020-12-24 12:20

    Lets come to the clear differences, without gigantic description..

    • A view is an object, can be put in layout or in pages. It is the basic building block for user interface components (you can refer these components as widget).
    • Widgets are small scale views(like button view, check box etc), that can be embedded in other views(like Home screen, login screen etc).

    Now you can think like , view is a container or place holder and widget is independent controls that you can place in any view.

    But keep in mind these are more like design concepts, not hardcore definitions.

    Finally, it can be concluded like,

    • An independent view, ready to use in any other views as an UI elements, can be referred as widget.

    For more explanation, have a look on basic code below:

    <!doctype html>
       <head>
          <title>New jQuery UI Widget by souro</title>
          <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
          <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
          <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
          <script>
             $(function() {
                $.widget("iP.myButton", {
                   _create: function() { 
                      this._button = $("<button>"); 
                      this._button.text("My first Widget Button");
                      this._button.width(this.options.width) 
                      this._button.css("background-color", this.options.color);    
                      this._button.css("position", "absolute");   
                      this._button.css("left", "100px");            
                      $(this.element).append(this._button);
                   },
                });
                $("#button1").myButton();
             });
          </script>
       </head>
       <body>
          <div id="button1"></div>
       </body>
    </html>

    Now you can see myButton is a small scale independent view i.e., widget and it is getting placed in a container button1 i.e, view, and yes you can put this widget in any other view i.e., purpose of widget. Make sense i guess.

    0 讨论(0)
  • 2020-12-24 12:25

    view is super class of widget so that a widget is a kind of view. In "pro android 4",the author take them as the same thing.

    "View,widget,control Each of these represents a UI element.Examples include a button,a grid,a list,a window,a dialog box,and so on.The terms view,widget,and control are used interchangeably in this chapter."

    0 讨论(0)
  • 2020-12-24 12:27

    Widget is package in Android which contain all user interfaces such button, textView and layout,etc. but view is an abstract class which includes properties, focus and event handling method ,rendering ,etc

    But all widgets extends the view for getting UI with it behavior such as properties, focus, etc.Thus all widgets are examples of view, but view is not the same as a widget. A View-group acts as container which contains different views examples are the frame-layout, relative-layout. They extend the view group and have as purpose as acting like a container which adds specific behavior to all the views it contains.

    0 讨论(0)
提交回复
热议问题