记得之前写过一篇博客叫做:
你还在苦逼地findViewById吗?使用ButterKnife从此轻松定义控件
此文是介绍在eclipse环境下使用ButterKnife的,相比传统的findViewById确实简单了点~但是笔者认为还不够简单~~
在谷歌停止对ADT+Eclipse停止更新之后~笔者还苦苦在Eclipse坚持了几个月终于开始转移到Android Studio上撸代码~~
因此本文也是在Android Studio基础上写的,如果有用Eclipse可以参考:
你还在苦逼地findViewById吗?使用ButterKnife从此轻松定义控件
ButterKnife简介
前面的文章已经介绍过了这里不介绍了!!!
ButterKnife+Android ButterKnife Zelezny组合
compile 'com.jakewharton:butterknife:7.0.1'
然后点击右上角的sync now,android studio就会自动下载ButterKnife<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<ImageView
android:id="@+id/testImageId"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/testTextId"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/testBtnId"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/testetId"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
按照传统做法我们是在Activity上一个个find出来,就只有这几个控件还好,但是我们写程序的时候有些界面远远不止这几个控件~~难道我们就一个个地find出来吗?