Android Basics Getting Started Tutorial--2.1 view vs. ViewGroup concept

Source: Internet
Author: User

Android Basics Getting Started Tutorial--2.1 view vs. ViewGroup concept

tags (space delimited): Android Basics Getting Started Tutorial

Introduction to this section:

Farewell to the first chapter, usher in the second chapter--android UI (User Interface) component of the detailed,
And what we're going to learn in this section is the parent view and ViewGroup class for all the controls! Whim, direct translation of official documents to
The introduction of these two things, right, the celestial reason, Google does not go on, Android developer not go on, we can
Change hosts or with a VPN proxy, of course, you can use the same as the author of the domestic API image, here to share:
Http://androiddoc.qiniudn.com/guide/topics/ui/overview.html
This image is 5.0 api!.

UI Overview

In the Android app, all user interface elements are composed of view and ViewGroup objects. View is an object that the user can interact with by drawing on the screen. ViewGroup is a layout container for storing other view (and ViewGroup) objects!
Android provides us with a collection of view and ViewGroup subclasses that provide some common input controls (such as buttons and text fields) and a variety of layout patterns (such as linear or relative layouts)

User Interface Layout

Each component of your app's user interface is constructed using the hierarchy of view and ViewGroup objects, such as
Figure 1. Each viewgroup is intended to be invisible to the container that is used to organize the child view, and its child view may be the input control
Or a widget for a block of areas is drawn on the UI. With a hierarchical tree, you can design simple or complex according to your own needs.
Clutter layout (The simpler the layout, the better the performance)


Figure 1 Illustration of a hierarchical structure of a UI layout

Define your layout, you can instantiate the view object in your code and start building your tree, but the easiest and most efficient way to define your layout is to use an XML file that makes the layout more consistent with the people's reading habits, while XML is similar to HTML
Use the name of an XML element to represent a view. So the < TextView > element creates a TextView control in your interface, and a < LinearLayout > creates a linearlayout container!
For example, a simple vertical layout has a text view and a button, just like this:

<?xml version= "1.0" encoding= "Utf-8"?><linearlayout  xmlns: Android  = "http://schemas.android.com/apk/res/android"  android:layout_width  =" fill_parent " android:layout_height  =" fill_parent " android:orientation  =;     <textview  android:id  = "@+id/text"  android:layout_width  =               "wrap_content"  android:layout_height  = "wrap_content"  
     
      android:text 
      = "I am a TextView" />     <button android:id="@+id/button"android:layout_width="Wrap_ Content "android:layout_height=" Wrap_content "android:text=" I am a button " />                                    </linearlayout>

When your app loads the above layout resources, Android instantiates each node in the layout into objects, and you can define some extra stars for these, query the state of the object, or modify the layout.
For a complete guide to creating a UI layout, refer to the XML Layouts

User Interface Components

You don't need to use the view and ViewGroup objects all to create your UI layout. Android gives us some app controls, a standard UI layout, you just need to define the content. These UI components have API documentation for their properties, such as the Action Bar, dialog box, status Notification bar, and so on.

This section summarizes:

Well, the translation may be more awkward, ah, English blind efforts, simple summed up the above content:

The graphical interface in Android is made up of view and ViewGroup and their subclasses:
View: parent class for all visual controls, providing component depiction and time-processing methods
ViewGroup: A subclass of the view class that can have child controls, which can be thought of as containers
Controls in the Android UI are stacked according to the structure of this hierarchical tree, and there are two ways to create a UI layout,
Write your own code in Java or define the layout through XML, which is more convenient and easy to understand!
is also our most commonly used means! In addition, we generally rarely use the view and viewgroup to write layouts, more
Use their sub-class controls or containers to build the layout!

Well, there is a general understanding of the view and viewgroup, usually we are not directly used, generally is the time to customize the view
Will only use these two things!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Basics Getting Started Tutorial--2.1 view vs. ViewGroup concept

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.