Basic tutorial for Android-2.1 concepts of View and ViewGroup, androidviewgroup

Source: Internet
Author: User

Basic tutorial for Android-2.1 concepts of View and ViewGroup, androidviewgroup
Basic tutorial for Android-2.1 concepts of View and ViewGroup

Tags (separated by spaces): basic Android tutorial

This section introduces:

Let's say goodbye to Chapter 1 and welcome to Chapter 2-detailed explanation of the UI (User Interface) component in Android,
In this section, we will learn the parent Class View and ViewGroup classes of all controls! A whimsy, directly translate the official documentation
Let's introduce these two things. By the way, why does tianchao go to google? Why does Android developer go to Android? We can
Change the hosts or use the vpn proxy. Of course, you can also use the domestic API image like the author. Here is an example:
Http://androiddoc.qiniudn.com/guide/topics/ui/overview.html
This image is 5.0 API!

UI Overview

In Android apps, all user interface elements are composed of View and ViewGroup objects. A View is an object that users can interact with on the screen. ViewGroup is a layout container used to store other View (and ViewGroup) objects!
Android provides a set of View and ViewGroup subclass, which provides some common input controls (such as buttons and text fields) and a variety of layout modes (such as linear or relative layout)

User Interface Layout

Every component on the user interface of your APP is composed of the View and ViewGroup object hierarchies, such
Figure 1. Each ViewGroup is a container for organizing sub-views that are invisible, and its sub-View may be an input control.
You can also draw widgets in a certain area on the UI. With the hierarchy tree, you can design simple or complex data based on your needs.
Complex layout (the simpler the layout, the better the performance)


Figure 1. Hierarchy illustration of a UI Layout

Define your layout. You can instantiate the View object in the Code and start building your tree. But the easiest and most efficient way to define your layout is to use an XML file, XML is used to make the layout more in line with people's reading habits, while XML is similar to HTML
The XML element name is used to represent a View. Therefore, the <TextView> element will create a TextView control in your interface, and a <LinearLayout> will create a LinearLayout container!
For example, a simple vertical layout contains a text view and a button, as shown below:

<?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="vertical" >    <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 will take each node in the layout as an object, and then you can define some extra stars for these nodes, query the object status or modify the layout.
Complete UI layout creation guide, refer to XML Layouts

User Interface Components

You do not need to use all View and ViewGroup objects to create your UI layout. Android provides some app controls and standard UI layout. You only need to define the content. These UI components have their attributes to introduce the API documentation, such as the operation bar, dialog box, and status notification bar.

Summary:

Well, the translation may be quite easy. Ah, I tried my best to make a mistake in English. I would like to briefly summarize the above content:

The GUI in Android is composed of View, ViewGroup, and their sub-classes:
View:Parent class of all visual controls, providing component profiling and Time Processing Methods
ViewGroup:A subclass of the View class, which can have sub-controls and can be viewed as containers.
Controls in the Android UI are stacked based on the hierarchy tree structure. There are two ways to create a UI layout,
You can write code in Java or define the layout through XML, which is more convenient and easy to understand!
It is also our most commonly used method! In addition, we rarely directly use View and ViewGroup to write the layout.
Use their subclass controls or containers to build the layout!

Well, you can have a general understanding of the View and ViewGroup. Normally, we do not use them directly.
These two items will be used!

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

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.