In Android, pack your custom components into jar packages.

Source: Internet
Author: User

During the project development process, we will inevitably use our own custom View Controls. Then, if needed, we will directly copy them to the corresponding project, although this is a solution to the problem, it is not very good after all.

The reason is that when our projects accumulate more and more, we will find more and more custom controls, and these custom controls can be reused, we can think about it, if we encapsulate all these custom controls into a jar package and accumulate them with a project, then we can expand or directly use the development project based on the original jar package, this greatly reduces repetitive work.

First, the basic features of the android project are as follows:

 

Of course, the corresponding activity file has been deleted, because when compiled into a jar package, we do not need the activity file.

The preceding project is used as an example to package it into a jar package. The steps are as follows:

Right-click the project and select export:

 

 

Select the export target: Java-> JAR file:

 

 

Check unnecessary files, such:

 

This step has been basically completed. Just browse and select the export path of the JAR file.

 

After the export is complete, we can use our own custom control package like other jar files. The following is a demo that describes how to use this jar package.

 

Step 1:

Create a folder lib and put the jar package into it.

Step 2:

Associate the jar package, for example:

 

 

Step 3: Use the jar package:

As follows:Code:

 <LinearlayoutXmlns: Android= "Http://schemas.android.com/apk/res/android"

Xmlns: GIF = "Http://schemas.android.com/apk/res/com.terry.jarTest"  
Android: ID = "@ + ID/layout" Android: Orientation = "Vertical"
Android: layout_width = "Fill_parent" Android: layout_height = "Fill_parent" >

<ButtonAndroid: Text= "Stop"Android: ID= "@ + ID/button01"
Android: layout_width= "Wrap_content"Android: layout_height= "Wrap_content"> </Button>
<ButtonAndroid: Text= "Start"Android: ID= "@ + ID/button02"
Android: layout_width= "Wrap_content"Android: layout_height= "Wrap_content"> </Button>

<Com.terry.gif. typegifview
Android: layout_width= "Fill_parent"Android: ID= "@ + ID/gifview1"
GIF: Stop= "True"Android: layout_height= "Wrap_content" 
GIF: Delay= "1"> </Com.terry.gif. typegifview>

</Linearlayout>

 

One bad thing is that if you use attributes in your project, you must copy them together to the project you want to use. Otherwise, you will not be able to recognize them.

Original article: http://www.cnblogs.com/terryblog/archive/2011/05/12/2044900.html
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.