The implementation method of the Android custom component into Jar package _android

Source: Internet
Author: User

The Android Custom component is implemented as a jar package , where you handle the jar package for your own implementation of the Android View component.

In the process of project development, we will inevitably use their own to make custom view control, then our other projects if necessary, directly copy it to the corresponding project to use, although this is a solution to the problem, but after all not very good.

The reason is that when our projects accumulate more and more, and we find that there are more and more custom controls, and that these custom controls are reusable, we can think about if you encapsulate these custom controls into a jar package and then accumulate them in one project, After we develop the project as long as the original jar package based on the expansion or direct use, can greatly reduce their duplication of work.

First, the basic features of Android engineering are this:

Of course, the corresponding activity file was deleted by me because we didn't need an activity file when compiling into a jar package.

Taking the above project as an example, we package it as a jar package step:

Right-key project selection export:

Select the export target: Java->jar file:

Check out some unnecessary files, as shown below:

To this step, has been basically completed, browse the selection Jar file export path can be.

Once the export is complete, we can use our own custom control packages just as we would with other jar files. Here's a little demo of how to use this jar package.

Step One:

Create a new folder Lib to put the jar package in.

Step Two:

The associated jar package, as shown in the following illustration:

Step three, use the jar package:

The following code:

 <linearlayout xmlns: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" >



  <button "Stop" Android:id= "@+id/button01"
    android:layout_width= "wrap_content" android:layout_height= "Wrap_content" >< /button>
  <button android: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 also copy the attributes to the project you want to use, otherwise you won't be able to identify them.

Thank you for reading, I hope to help you, thank you for your support for this site!

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.