`
xsuo
  • 浏览: 119324 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

屏幕元素的层次

阅读更多

屏幕元素的层次

The basic functional unit of an Android application is the activity--an object of the class android.app.Activity. An activity can do many things, but by itself it does not have a presence on the screen. To give your activity a screen presence and design its UI, you work with views and viewgroups -- basic units of user interface expression on the Android platform.

Android应用程序的基础功能单元就是Activity--android.app.Activity类中的一个对象。一个Activity可以做很多事,但是他自己并不会显示到屏幕上。想要让你的Activity显示在屏幕上并且设计它的UI,你需要使用view和viewgroup--Android平台基础的用户界面表达单元。


Views

A view is an object of base class android.view.View. It's a data structure whose properties store the layout and content for a specific rectangular area of the screen. A View object handles measuring and layout, drawing, focus change, scrolling, and key/gestures for the screen area it represents.

一个view是一个android.view.View基础类的对象。它是一个存储有屏幕上特定的一个矩形内布局和内容属性的数据结构。一个View对象处理测距和布局,绘图,焦点变换,滚动条,还有屏幕区域自己表现的按键和手势。

The View class serves as a base class for widgets -- a set of fully implemented subclasses that draw interactive screen elements. Widgets handle their own measuring and drawing, so you can use them to build your UI more quickly. The list of widgets available includes Text, EditText, InputMethod, MovementMethod, Button, RadioButton, Checkbox, and ScrollView.

View类作为一个基类为widget(窗体部件)服务,widget--是一组用于绘制交互屏幕元素的完全实现子类。Widget处理它们自己的测距和绘图,所以你可以更快速地用它们去构建你的UI。可用到的widget包括Text,EditText,InputMethod,Button,RadioButton,Checkbox,和ScrollView。

Viewgroups

A viewgroup is an object of class android.view.Viewgroup. As its name indicates, a viewgroup is a special type of view object whose function is to contain and manage a subordinate set of views and other viewgroups, Viewgroups let you add structure to your UI and build up complex screen elements that can be addressed as a single entity.

一个ViewGroup是一个android.view.Viewgroup类的对象。正如同它的名字表明的一样,一个viewgroup是一个特殊的view对象,它的功能是去装载和管理一组下层的view和其他viewgroup,Viewgroup让你可以为你的UI增加结构并且将复杂的屏幕元素构建成一个独立的实体。

The Viewgroup class serves as a base class for layouts -- a set of fully implemented subclasses that provide common types of screen layout. The layouts give you a way to build a structure for a set of views.

Viewgroup类作为一个基类为layout(布局)服务,layout--是一组提供屏幕界面通用类型的完全实现子类。layout让你可以为一组view构建一个结构。


A Tree-Structured UI

On the Android platform, you define an Activity's UI using a tree of view and viewgroup nodes, as shown in the diagram below. The tree can be as simple or complex as you need to make it, and you can build it up using Android's set of predefined widgets and layouts or custom view types that you create yourself.

在Android平台上,你用view树和viewgroup节点来定义一个Activity的UI,就如同下面图表一样。这个树可以如你需要那样简单或者复杂,并且你可以使用Android的预定义widget和layout或者你自定义的view类型来构建它。

An example of a tree of views and viewgroups 一个view和viewgroup树的样例

http://code.google.com/android/images/viewgroup.png

To attach the tree to the screen for rendering, your Activity calls its setContentView() method and passes a reference to the root node object. Once the Android system has the reference to the root node object, it can work directly with the node to invalidate, measure, and draw the tree. When your Activity becomes active and receives focus, the system notifies your activity and requests the root node to measure and draw the tree. The root node then requests that its child nodes draw themselves -- in turn, each viewgroup node in the tree is responsible for drawing its direct children.

要将屏幕绑定一个树以便于渲染,你的Activity调用它的setContentView()方法并且传递一个参数给根节点对象。一旦Android系统获得了根节点的参数,它就可以直接通过节点来无效化,测距和绘制树。当你的Activity被激活并且获得焦点时,系统会通知你的activity并且请求根节点去测距并绘制树,根节点就会请求它的子节点去绘制它们自己。每个树上的viewgroup节点都为它的子节点的绘制负责。

As mentioned previously, each view group has the responsibility of measuring its available space, laying out its children, and calling Draw() on each child to let it render itself. The children may request a size and location in the parent, but the parent object has the final decision on where how big each child can be.

正如之前提到的,每个view group都有测量它的有效空间,布局它的子对象,并且调用每个子对象的Draw()方法去绘制它们自己。子对象可能会请求获得一个它们在父对象中的大小和位置,但是父对象对于每个子对象的大小和位置有最终的决定权。

LayoutParams:一个子对象如何指定它的位置和大小

Every viewgroup class uses a nested class that extends ViewGroup.LayoutParams. This subclass contains property types that define a child's size and position, in properties appropriate for that view group class.

每个viewgroup类都会使用一个继承于Viewgroup.LayoutParams的嵌套类。这个子类包含了包含了定义一个子对象位置和大小的属性类型,并且需适用于view group类。

An example of layoutparams

layoutparams的一个样例

<img src="http://code.google.com/android/images/layoutparams.png" />

Note that every LayoutParams subclass has its own syntax for setting values. Each child element must define LayoutParams that are appropriate for its parent, although it may define different LayoutParams for its children.

要注意的是,每个LayoutParams子类都有它自己赋值的语法。每个子元素必须定义适用于它们父对象的LayoutParams,尽管父对象可能会为子元素定义不同的LayoutParams。

All viewgroups include width and height. Many also include margins and borders. You can specify width and height exactly, though you probably won't want to do this often. More often you will tell your view to size itself either to the dimensions of its content, or to become as big as its containing object will allow.

所有的viewgroup都包括宽和高。很多还包括边界的定义(margin和border)。你可以非常精确地描述宽和高,尽管你并不想经常这么做。更多时候你希望你的view自行调整到适应内容大小,或者适应容器大小。

分享到:
评论

相关推荐

    andbook中文版

    17 Content Provider………………………………………………………18 Android 用户界面………………………………… 19 屏幕元素层次…………………………………………………………19 Android UI 元素与Swing UI 元素...

    js对象层次• navigator •screen•window

    屏幕对象 窗口对象  历史对象  地址对象  框架对象  文档对象  连接对象  Java小程序对象  插件对象  表单对象  按钮对象  复选框对象  表单元素对象  隐藏对象  密码输入区对象  单选域对象  重置...

    UISpy2018之UIAutomation元素查看器

    通过查看应用程序的 UI 层次结构、属性值和引发的事件,开发人员和测试人员将能够验证辅助技术设备(如屏幕阅读器)是否能够以编程方式访问他们创建的 UI。 UI Spy 使用 UI 自动化库。UI 自动化是 Microsoft Windows...

    IPHONE用户界面设计典型实例

    【作 者】(美)巴纳德等著 ...主要包括以下内容:优化使用有限的屏幕面积,让 屏幕上的元素清晰显示,创建吸引眼球的用户界面/让你的应用程序在小屏幕上的一大堆界面中突出显示,让各界面之间的层次感更清晰。

    Android studio界面设计与资源PPT

    (1)理解Android屏幕元素的层次结构、View与ViewGroup (2)熟悉Android的布局对象和Android中创建UI界面的方式 (3)熟悉Android常用的UI控件及其基本属性 (4)熟悉Android尺寸的单位 (5)掌握TextView、...

    uispy.exe+inspect.exe

    通过查看应用程序的 UI 层次结构、属性值和引发的事件,开发人员和测试人员将能够验证辅助技术设备(如屏幕阅读器)是否能够以编程方式访问他们创建的 UI。inspect.zip包括inspect.exe,inspect32.exe,32位和64位

    uispy+inspect.rar

    通过查看应用程序的 UI 层次结构、属性值和引发的事件,开发人员和测试人员将能够验证辅助技术设备(如屏幕阅读器)是否能够以编程方式访问他们创建的 UI。inspect.zip包括inspect.exe,inspect32.exe,32位和64位

    Fragment+ActionBar

    因为现在设备的屏幕越来越大,使用Fragment可以更灵活的管理视图层次的变化。像Activity一样,可以创建Fragment来包含View,进行布局,但是Fragment必须嵌入在Activity中,不能单独存在,而且一个Activity可以嵌入多...

    程序UI界面与源码查看器(UISPY).rar

    通过查看应用程序的UI层次结构,属性值和引发的事件,开发人员和测试人员可以验证其创建的UI是否可以通过编程方式访问辅助技术设备(例如屏幕阅读器)。 UI Spy使用UI自动化库。UI自动化是Microsoft Windows的新...

    Rooler-crx插件

    -测量图形的边界-测量图形之间的距离-即使在深度嵌套的元素层次结构中,也可以确保元素的正确定位。 快速简便。 试一试。 您也可以在浏览器中通过以下网址尝试Rooler:http://peteblois.github.io/rooler.js。

    滚柱「Rooler」-crx插件

    -测量图形的边界-测量图形之间的距离-即使在深度嵌套的元素层次结构中,也可以确保元素的正确定位。 快速简便。 试一试。 您也可以在浏览器中通过以下网址尝试Rooler:http://peteblois.github.io/rooler.js。 支持...

    UISpy(因原来提供的UISpy无法下载)

    通过查看应用程序的 UI 层次结构、属性值和引发的事件,开发人员和测试人员将能够验证辅助技术设备(如屏幕阅读器)是否能够以编程方式访问他们创建的 UI。 UI Spy 使用 UI 自动化库。UI 自动化是 Microsoft ...

    iOS-Hierarchy-Viewer:iOS层次结构查看器-简化View和Coredata调试

    适用于UI和CoreData的iOS层次结构查看器iOS Hierarchy Viewer允许开发人员调试UIView和CoreData模型的层次结构。 如果布局计算存在问题,则可以通过在浏览器中内省视图的实时预览来轻松找到它们。 如果您的数据表现...

    Skimmet-crx插件

    屏幕元素带来的重量和层次结构将吸引他的注意力。 在模糊模式下评估屏幕可以帮助您&gt;分析可见屏幕空间中区域/元素的眼睛吸引。 &gt;感觉到号召性用语的力量。 &gt;预期撇渣器的眼球运动。 &gt;您的文章可能包含多级标题。 在...

    CantTakeItAnymore:2d 自上而下的射击游戏 w rpg 元素。 当倒计时结束时,要么面对老板,要么以增加难度为代价重置

    带有 rpg 元素的 2d 自上而下的射击游戏。 当你的时间用完时准备打bo​​ss,如果你没有准备好,你可以重置,但难度会增加。 为:UMD Game Dev Club 的 Game Jam 开发主题:倒计时 开发商: 张世良 (lsftw) 陈哲豪...

    treenav:该库允许您显示树数据结构中的层次结构信息

    TreeNav 该库使您可以在垂直滚动列表中显示层次结构信息(来自树数据结构)。 如果您需要不同类型的单元格,则还可以灵活地定义自定义布局。 ===============屏幕截图用法为了使用该库,您将需要: 使用类NAryTree和...

    Android入门到精通

    8.1 Android的屏幕元素体系 8.2 几种独立使用的视图组 8.3 作为简单容器使用的视图组 8.4 布局(Layout) 8.5 网格(Grid)视图组 8.6 列表(List)视图组 8.7 使用Tab组织UI 第9章 2D图形接口的使用 9.1 使用2D...

    C++ 数据库二叉树的实现

    一、实验目的 ...4、编写按照层次遍历二叉树的算法,并显示遍历后的结点序列。(利用队列) 5、编写算法判定给定二叉树是否为完全二叉树。 6、编写递归算法,求二叉树中以元素值为x的结点为根的子树的深度。

    Visual C++ MFC 简明教程

    要记住的是,作为程序员必须选择一组控制并决定如何把它们安排到屏幕上。传统上,你需要在纸上做一下用户界面的草图,直到对各元素感到满意为止。这对于一些比较小的项目,以及一些大项目的早期原型阶段是可以的。

Global site tag (gtag.js) - Google Analytics