Because in the development process, in order to achieve an unknown effect and a specific function, and to turn to the online excellent open source projects, in the process of using the discovery of Open Source Library project (library projects), it can solve a lot of problems, but also gives a way of thinking, Good software companies also need to have their own library project (library projects), so that unnecessary duplication of development work, this is just their own ideas. The following will be their own experience or experience recorded as follows, the following is their own writing style.
"Reproduced use, please specify the source:http://blog.csdn.net/mahoking/article/details/36405219"
Application Scenarios:In the project development process, often use the company's internal public library or use a good open source project library, in order to achieve rapid development, code reuse effect. Projects that are being developed to integrate other projects because of the large integration project, do not want to copy the mechanical, you want to integrate the project into the project library. Based on this requirement, referencing the library project is an urgent need, so it is easy and fast to upgrade and expand the integration project later. To do this, we have to understand the creation and reference operations of the Android Library project (library projects). "Reproduced use, please specify the source:http://blog.csdn.net/mahoking/article/details/36405219"
How to use:First step: Create the Project Mylib, "Next".
The second step: The red part is unchecked, uncheck [Create custom Launcher icon] and [create activity], tick [make this project as a library].
The third step: first build the package name, add the Myimageview.java file. "Myimageview.java to quote someone else's code and thank you for that. 】
Package Com.example.lib;import Android.content.context;import Android.graphics.matrix;import Android.graphics.drawable.bitmapdrawable;import Android.graphics.drawable.drawable;import Android.os.Handler; Import Android.util.attributeset;import Android.view.motionevent;import Android.widget.imageview;public class Myimageview extends ImageView {private static final String TAG = "Myimageview";p rivate static final int scale_reduce_init = 0;private static final int SCALING = 1;private static final int scale_add_init = 6;/** * control's width */private int mwidth;/*** control High */private int mheight;/*** control's width 1/2*/private int mcenterwidth;/*** control's high 1/2*/private int mcenterheight;/*** set a scaled constant * /private float Mminscale = 0.85f;/*** Zoom End */private Boolean isfinish = True;public Myimageview (context context) {This (CO ntext, null);} Public Myimageview (context context, AttributeSet Attrs) {This (context, attrs, 0);} Public Myimageview (context context, AttributeSet attrs, int defstyle) {Super (context, attrs, Defstyle);} /** * Necessary initialization */@Overrideprotected void OnLayout (Boolean changed, int left, int top, int right,int bottom) {super.onlayout (ch Anged, left, top, right, bottom), if (changed) {mwidth = GetWidth ()-Getpaddingleft ()-getpaddingright (); mheight = Gethei Ght ()-Getpaddingtop ()-Getpaddingbottom (); mcenterwidth = Mwidth/2;mcenterheight = mheight/2;drawable Drawable = Get Drawable (); bitmapdrawable BD = (bitmapdrawable) Drawable;bd.setantialias (True);}} @Overridepublic boolean ontouchevent (Motionevent event) {switch (event.getaction ()) {case Motionevent.action_down: float X = Event.getx (); Float Y = Event.gety (); Mscalehandler.sendemptymessage (scale_reduce_init); break;case MotionEvent.ACTION_UP:mScaleHandler.sendEmptyMessage (scale_add_init); break;} return true;} /** * Control scaled Handler */private Handler mscalehandler = new Handler () {private Matrix matrix = new Matrix ();p rivate int Count = 0;private Float s;/** * has been called Click event */private boolean isclicked;public void Handlemessage (Android.os.Message msg) {MatRix.set (Getimagematrix ()); switch (msg.what) {case Scale_reduce_init:if (!isfinish) {mscalehandler.sendemptymessage ( Scale_reduce_init);} else {isfinish = False;count = 0;s = (float) math.sqrt (math.sqrt (Mminscale)); Beginscale (Matrix, s); Mscalehandler.sendemptymessage (SCALING);} Break;case Scaling:beginscale (Matrix, s); if (Count < 4) {mscalehandler.sendemptymessage (SCALING);} else {isfinish = True;if (MyImageView.this.mOnViewClickListener! = null&&!isclicked) {isclicked = true; MyImageView.this.mOnViewClickListener.onViewClick (myimageview.this);} else {isclicked = false;}} Count++;break;case Scale_add_init:if (!isfinish) {mscalehandler.sendemptymessage (scale_add_init);} else {isFinish = False;count = 0;s = (float) math.sqrt (math.sqrt (1.0f/mminscale)); Beginscale (Matrix, s); Mscalehandler.sendemptymessage (SCALING);} break;}}; protected void sleep (int i) {try {thread.sleep (i);} catch (Interruptedexception e) {e.printstacktrace ()}} /** * Zoom * * @param matrix * @param scale */private synchronized void Beginscale (matrix matrix, float scale) {Matrix.postscale (scale, scale, mcenterwidth, mcenterheight); Setimagematrix (matrix);} /** * Callback interface */private onviewclicklistener monviewclicklistener;public void Setonclickintent (Onviewclicklistener Onviewclicklistener) {this.monviewclicklistener = Onviewclicklistener;} public interface Onviewclicklistener {void Onviewclick (Myimageview view);}}
Fourth Step: Create another project myproj, tick [Create custom launcher icon] and [Create activity], uncheck [Make this project as a library].
Fifth step: Referencing the Mylib project.
Sixth step: Write the Activtiy_main.xml and the corresponding activity.
"Activtiy_main.xml"
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" match_parent " android:layout_height=" Match_parent " android:gravity= "center" tools:context= ". Mainactivity "> <com.example.lib.myimageview android:layout_height=" Wrap_content " android: Layout_width= "Wrap_content" android:scaletype= "Matrix" android:src= "@drawable/chat_004" android: Id= "@+id/myimageview"/></relativelayout>
"Mainactivtiy.java"
Package Com.example.myproj;import Com.example.lib.myimageview;import Com.example.lib.myimageview.onviewclicklistener;import Android.os.bundle;import Android.app.Activity;import Android.widget.toast;public class Mainactivity extends Activity {private Myimageview imageView; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Initviews ();} private void Initviews () {ImageView = (Myimageview) Findviewbyid (R.id.myimageview); Imageview.setonclickintent (new Onviewclicklistener () {@Overridepublic void Onviewclick (Myimageview view) {Toast.maketext (Getapplicationcontext (), " You touched this lovely expression! ", Toast.length_short). Show ();}});}}
Seventh Step: Run the project MyProj, the following effect appears.
======= Click to download ======="Reproduced use, please specify the source:http://blog.csdn.net/mahoking/article/details/36405219"
Resources1, http://blog.sina.com.cn/s/blog_783ede0301016ip2.html