A more concise annotation framework than butterKnife

1. Introduction to the framework:


        The feature of Annotation is to make the code more concise, reduce the coupling of the code, improve the compilation efficiency of the code, and improve the development efficiency. Compared with butterknife, the setLayout() annotation is added. The purpose is to omit the layout filling code. The following describes Activity and Fragment respectively: 1. Omit in activity: setContentView(); 2. Omit inflate() in fragment; In fact, it is not really omitted, but will be encapsulated in the Annotation framework using reflection, so the question is, how to add the layout to this class? This is what I just said about adding the setLayout() annotation. The annotation is in front of the class. As soon as the class is opened, the layout of the class can be seen at a glance. The details have been introduced in detail in the usage method.

      Using the Annotation framework makes personal recommendations encapsulate it into BaseActivity and BaseFragment to avoid some duplication of code.
      When encapsulating BaseActivity , initialize it in the onCreate method: Annotation.init(this); 
      When encapsulating BaseFragment, encapsulate the inflateView() method, but do not encapsulate Annotation.bind(this) into onCreateView(), because onCreateView() needs to return A view object. At this time, you need to pass the View returned by Annotation.bind() to onCreateView();

Second, the introduction method:


method one:

Add in the dependencies directory of the module's build.gradle file:
compile 'com.suhu:Annotations:v1.0.0'
(in the default jcenter library of Android studio, so it only takes one step)

Method two:

1. Add in the repositories directory of the project's build.gradle file: maven{url ' https://jitpack.io'}
2. Add in the dependencies directory of the module's build.gradle file:
compile 'com.github. suhuMM:Annotations:v1.0.0'

For eclipse friends :
students who use eclipse, please copy the jar package in the Annotations/app/libs/ directory: annotation.jar

3. How to use:


Use in activity:

1. Implement the interface: IALayoy
2. Initialize in the onCreate method: Annotation.init(this);


Use in fragment:

1. Implement interface: IFLayout
2. Rewrite method: inflateView and return: return View.inflate(getActivity(), layout, null);
3. Initialize in onCreateView method: Annotation.bind(this);


4. Method introduction


Activity initialization method: init()


Fragment initialization method: bind()


5. Version information


v1.0.0 version information:
        v1.0.0 is also the initial version. This version mainly has two major modules: 1. Layout loading (setLayout annotation) 2. Control loading (bindView annotation)

6. Related documents


github address: https://github.com/suhuMM/Annotations

My short book address: http://www.jianshu.com/p/9fa7916d8de8

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325987824&siteId=291194637