记得很早之前有个xutils框架,就有这个功能,但是它是通过反射和代理发生在运行时期,所以效率肯定没butterknife框架效率高,今天就简单入门,如何使用:github:https://github.com/JakeWharton/butterknife
使用三方框架看下它提供的步骤就行,然后按照说的步骤一步步来一般就ok,
第一步:
dependencies { compile 'com.jakewharton:butterknife:8.8.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' }
添加这二个,这是目前最新的
第二步:
To use Butter Knife in a library, add the plugin to your buildscript
:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
}
}
看下我的配置:
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { mavenCentral() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }
第三步:
and then apply it in your module:
<