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