Android的UI两大基石

    说到Android的UI就不得不从一切的开始View开始说。
    让我们从Android Developer上的View的Overview和UI Overview来开始吧。
   
Class Overview
    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.
    UI Overview
    All user interface elements in an Android app are built using View and ViewGroup objects. A View is an object that draws something on the screen that the user can interact with. A ViewGroup is an object that holds other View (and ViewGroup) objects in order to define the layout of the interface.
    Android provides a collection of both View and ViewGroup subclasses that offer you common input controls (such as buttons and text fields) and various layout models (such as a linear or relative layout).
    通过这两段Overview,我们了解到View是UI的最基本组件,是所有控件布局的超类。它是一切开始的基本。
    接着,该说到ViewGroup了。
    java.lang.Object
       ---android.view.View
            ---android.view.ViewGroup
    Class Overview
    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.
    ViewGroup继承自View,是一类特别的View,特别是因为他能包含其他View,是作为一种容器而存在。
    下面要引用一张Android Developer上经典的老图了:




    这张图说明View和ViewGroup是如何组合成一个完整的视图的,这里使用了一种叫做组合的设计模式。我们来看看这种设计模式在wiki上的定义:
    组合模式:把多个对象组成树状结构来表示局部与整体,这样用户可以一样的对待单个对象和对象的组合。
    View和ViewGroup就是基于这种设计模式的设计的,好处在于对ViewGroup来说它将它的子节点全都当成View而不关心它子节点到底是View还是ViewGroup。
    View和ViewGroup组成了Android的UI的基石,UI设计也就是设计出一棵View树。

---------------------------------------------------------------------------------------------------------------
    如果文中有任何错误,欢迎指出。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值