Android中的视图和小部件有什么区别?
View
和Android中的小部件之间有什么区别?
What is the difference between a View
and widget in Android?
如 View
类文档中所述:
此类代表用户界面组件的基本构建块.
View
占据屏幕上的矩形区域,并负责绘图和事件处理.View
是窗口小部件的基类,窗口小部件用于创建交互式UI组件(按钮,文本字段等).
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.).
ViewGroup
子类是布局的基类,布局是包含其他 View
s(或其他 ViewGroup
s)和定义其布局属性.
The ViewGroup
subclass is the base class for layouts, which are invisible containers that hold other View
s (or other ViewGroup
s) and define their layout properties.
因此, View
是UI元素的基类, Widget 被宽松定义为 任何可使用的 View
.
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
是所有UI元素的基类.因此,它涵盖了许多不同的类和概念,包括小部件, ViewGroup
和布局.在Window实例上附加了根 View
,它构成了 View
层次结构的基础.通常, View
一词通常用于描述UI元素,或用于引用抽象或基础UI类,例如 ViewGroup
s.
A View
is a base class for all UI elements. It, therefore, covers many different classes and concepts, including widgets, ViewGroup
s 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 ViewGroup
s.
该术语有各种定义,但是大多数是指准备使用".UI元素,例如 Button
, ImageView
, EditText
等.请注意,有些人认为小部件是完整的UI元素(不是而不是容器(例如 ViewGroup
(布局/ ListViews
)).还值得注意的是,小部件"是程序包名称( android.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 ViewGroup
s (layouts/ListViews
)). It's also worth noting that "widget" is a package name (android.widget
) where the docs mention the following:
小部件包包含(大部分是可视的)UI元素,可在应用程序"屏幕上使用.
The widget package contains (mostly visual) UI elements to use on your Application screen.
因此,将非可视UI元素也视为小部件以及在小部件包下定义的任何类是合理的.请参阅此处以获取小部件包中类的完整列表: http://developer.android.com/reference/android/widget/package-summary.html
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
不要与UI元素小部件混淆,应用小部件是远程的 View
层次结构,通常显示在用户的主屏幕上.根据文档的定义:
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窗口小部件是微型应用程序视图,可以嵌入其他应用程序(例如主屏幕)中并接收定期更新.这些视图在用户界面中称为Widget,您可以使用App Widget提供程序发布这些视图.能够容纳其他App Widget的应用程序组件称为App Widget主机.
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
ViewGroup
是 View
的子类,并提供了对子 View
进行父代和定位的功能,例如在Layouts的情况下
ViewGroup
A ViewGroup
is a subclass of View
and provides the ability to parent and position child View
s, such as in the case of Layouts.
与Widgets一样,它没有Layout基类,因此可以将其宽松地定义为扩展 ViewGroup
并提供定义子 View位置的功能的任何类其中的代码.通常,只有
ViewGroup
子类附加了单词"Layout",(如 LinearLayout
, RelativeLayout
中)称为布局",扩展 ViewGroup
的其他类通常仅称为"view"容器".
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 View
s 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.