Danh mục

Android - Giao diện người dùng sử dụng XML Layouts

Số trang: 67      Loại file: pdf      Dung lượng: 2.44 MB      Lượt xem: 11      Lượt tải: 0    
tailieu_vip

Xem trước 7 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Các lớp học Xem đại diện cho khối xây dựng cơ bản cho các thành phần giao diện người dùng. Xem A chiếm một diện tích hình chữ nhật trên màn hình và chịu trách nhiệm cho các bản vẽ và xử lý sự kiện. Xem là lớp cơ sở cho các vật dụng, được sử dụng để tạo ra các thành phần giao diện tương tác (các nút, các trường văn bản, vv.) Các lớp con ViewGroup là lớp cơ sở để bố trí, được đựng vô hình mà giữ Lượt xem khác (hoặc các ViewGroups) và xác định...
Nội dung trích xuất từ tài liệu:
Android - Giao diện người dùng sử dụng XML Layouts Android – User Interfaces Using XML Layouts Notes are based on: The Busy Coder's Guide to Android Development by Mark L. Murphy Copyright © 2008-2009 CommonsWare, LLC. ISBN: 978-0-9816780-0-9 & Android Developers http://developer.android.com/index.html Android – UI - User Interfaces The View Class • The View 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. 2 Android – UI - User Interfaces Using Views All of the views in a window are arranged in a single tree. You can add views either from code or by specifying a tree of views in one or more XML layout files. Once you have created a tree of views, there are typically a few types of common operations you may wish to perform: 1. Set properties: for example setting the text of a TextView. Properties that are known at build time can be set in the XML layout files. 2. Set focus: The framework will handled moving focus in response to user input. To force focus to a specific view, call requestFocus(). 3. Set up listeners: Views allow clients to set listeners that will be notified when something interesting happens to the view. For example, a Button exposes a listener to notify clients when the button is clicked. 4. Set visibility: You can hide or show views using setVisibility(int). 3 Android – UI - User Interfaces A brief sample of UI components Layouts Linear Layout Relative Layout Table Layout A LinearLayout is a A RelativeLayout is a ViewGroup A TableLayout is a GroupView that will lay that allows you to layout child ViewGroup that will lay child View elements elements in positions relative to child View elements into vertically or horizontally. the parent or siblings elements. rows and columns. 4 Android – UI - User Interfaces A brief sample of UI components Widgets GalleryView TabWidget Spinner DatePicker Form Controls A DatePicke is a widget Includes a variety of typical that allows the user to form widgets, like: select a month, day and image buttons, year. text fields, checkboxes and radio buttons. 5 Android – UI - User Interfaces A brief sample of UI components WebView MapView AutoCompleteTextView ListView It is a version of the EditText A ListView is a View that widget that will provide shows items in a vertically auto-complete suggestions scrolling list. The items are as the user types. The acquired from a ListAdapter. suggestions are extracted from a collection of strings. 6 Android – UI - User Interfaces What is an XML Layout? An XML-based layout is a specification of the various UI components (widgets) and the relationships to each other – and to their containers – all written in XML format. Android considers XML- based layouts to be resources, and as such layout files are stored in the res/layout directory inside your Android project. 7 Android – UI - User Interfaces What is an XML Layout? ASIDE You could create Layout XML files using UI tools such as: • Eclipse ADT UI Designer (getting better but still…) DroidDraw (http://www.droiddraw.org/) • Asset Studio (http://android-ui-utils.googlecode.com/ • hg/asset-studio/dist/index.html) 8 Android – UI - User Interfaces What is an XML Layout? Each XML file contains a tree of elements specifying a layout of widgets and containers that make up one View (shown later). The attributes of the XML elements are properties, describing how a widget should look or how a container should behave. Example: If a Button element has an attribute value of android:textStyle = bold that means that the text appearing on the face of the button should be rendered in a boldface font style. 9 Android – UI - User Interfaces An exampl ...

Tài liệu được xem nhiều: