記得之前寫過一篇博客叫做:
你還在苦逼地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出來嗎?