Android Learning View and Composite Application

Source: Internet
Author: User

One composite mode

Combine objects into a tree structure to represent the "part-whole" hierarchy.

Composite makes the use of operations on a single object and the combined object consistent.

This involves the operation of a single object and a composite object.

The consistent treatment of a single object and a combination object enables: customerCodeConsistent and simple,

It is more flexible to use, so it is easy to expand new composite objects and facilitate object management.

To treat a single object and composite object in a unified manner, it is necessary to provide the need for some composite objects.A single object does not require operations, attributes, and other management methods,

These methods may not exist or are not applicable to a single object,In this way, there will inevitably be some potential risks, resulting in the existence of insecure factors.

However, there must be some differences between a single object and a composite object. You must treat a single object as a composite object,

Transparency is selected in security and transparency. If security is selected, a single object and a composite object must be treated differently.

There is a lot of uncertainty, but it can be determined that a composite object has a way to manage subobjects.

Next, let's take a look at the view class hierarchy in Android.

2. View Management in Android

The basic class of the control used for display in adnroid is view. Many basic widgets are as follows:

Imageview and textview are derived directly from view, and other controls that support combination are derived from viewgroup.

Controls class hierarchies such:

Therefore, in the combination mode of View in Android, single objects and composite objects are partially treated differently:

A single object is derived from the view or continues to be derived. A combination object is derived from the viewgroup to receive a single object.

However, this difference is limited to a single object or a combination object, but it is still a view after all. So it is partially treated differently.

The following describes how to manage viewgroup sub-objects.

3.ViewgroupManage Sub-objects

Viewgroup is an abstract class used to manage the containers of controls on the next layer, including basic controls and composite controls.

The five layout s inherited from viewgroup are: framelayout (Framework layout), linearlayout (linear layout ),

Absolutelayout (absolute layout), relativelayout (relative layout), tablelayout (table layout), listview, and gridview.

Viewgroup's subclass management seems simple and uses an array for management.

The viewgroup class has one member:Private view [] mchildren; Is used to save all the sub-objects on it;

If the initial size is 12 or more, abandon the application again. This may be the convenience of using Java memory management. You do not have to take the initiative to destroy the sub-objects of viewgroup.

There is a member in the View:Protected viewparent mparent; Specifies the unique parent for each view.

 

As for the advantages of differentiated treatment: to meet the security mentioned in the mode, after all, there is a difference between a single object and a composite object,

The operations on composite objects are more complex, and the sub-objects need to be managed: Display attributes and focus event handling and distribution. However, a single object obviously does not need to have these features,

If you do not need to distinguish between potential security risks and unnecessary complexity of a single object, you will not be informed of the other reasons. We look forward to your answers.

 

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.