Layoutinflater Layout Manager

Source: Internet
Author: User

The Layoutinflater function is to instantiate an XML layout file of layout as a view class object.

There are 3 ways to achieve layoutinflater instantiation,

(1). Obtained by Systemservice

Layoutinflater Inflater = (layoutinflater) context.getsystemservices (context.layout_inflater_services);

View view = Inflater.inflate (R.layout.main, NULL);

(2). Get from a given context

Layoutinflater Inflater = layoutinflater.from (context);

View view = Inflater.inflate (R.layout.mian, NULL);

(3).

Layoutinflater inflater =getlayoutinflater (); (can be used in activity, is actually a function of the window under the view sub-class)

View layout = inflater.inflate (R.layout.main, NULL);


In fact, these three kinds of ways are essentially the same, from the source can be seen:

Getlayoutinflater ():

The Getlayoutinflater () method of the activity is to call Phonewindow's Getlayoutinflater () method and take a look at the source code:

Public Phonewindow (Context context) {

Super (context);

Mlayoutinflater = Layoutinflater.from (context);

}

It can be seen that it is actually called layoutinflater.from (context).

Layoutinflater.from (context):

public static Layoutinflater from (context context) {

Layoutinflater Layoutinflater = (layoutinflater) context.getsystemservice (Context.layout_inflater_service);

if (Layoutinflater = = null) {

throw new Assertionerror ("Layoutinflater not Found.");

}

return layoutinflater;

}

It can be seen that it actually calls Context.getsystemservice ().

Public View Inflate (int resourece,view grouproot)
Role: Populates a new view hierarchy from the specified XML resource file
The ID of the Resource:view layout
Root: Rooted view of the resulting hierarchy
Return fills the root view of the hierarchy. If the parameter root is provided, then root is the root view, otherwise the root of the populated XML file is the root view.

The inflate functions are similar for the remaining several overloads.

added in addition, Getsystemservice is a method in activity that obtains a corresponding service object based on the name passed in, and these service name parameters are constants in the context class:

Description of the object returned by the incoming name
Window_service WindowManager managing open Windows programs
Layout_inflater_service Layoutinflater Gets the view defined in the XML
Activity_service Activitymanager managing the System state of an application
Power_service Powermanger power Supply Services
Alarm_service Alarmmanager Alarm Clock Service
Notification_service Services for Notificationmanager status bar
Keyguard_service Keyguardmanager Keypad Lock Service
Location_service Locationmanager Location Services, such as GPS
Search_service Searchmanager Search for services
Vebrator_service vebrator mobile phone Shake service
Connectivity_service CONNECTIVITY Network-connected services
Wifi_service Wifimanager Wi-Fi service
Telephony_service Teleponymanager Telephone Service



Layoutinflater Layout Manager

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.