Customizing a composite Control

Source: Internet
Author: User

In the case of the same layout (XML) When you write the Android program, we need to do some encapsulation in order to increase the reusability of the code, including two cases:

One: If you have a different layout that contains the same simple layout, you can extract code from the simple layout, such as: Mainactivity.xml and Setting.xml file, there is a titlebar layout, we can extract the titlebar, separate as a titlebar.xml file, and then where needed to use <include android:layout= "@ Layout.titlebar "/> Introduced

Second: If the included layout is relatively complex, you can populate it with one as a control, and for titlebar, all we need to do is define a subclass of ViewGroup, And in its construction method, forcing him to fill a layout in his own area (View.inflater (Context,r.layout.titlebar,this,false) where this represents the parent container, which is the component itself. So each time you load a view, it forces you to load a view style that you've set. Finally, you only need to write this view in the layout file.

Customizing a composite Control

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.