1.Android Layout ID Converter 把佈局的view通過findviewById找到。
使用方法:在你的佈局文件當中右鍵,在彈出來的菜單當中選擇Convert Android layout xml,如下圖所示:
然後它會彈出一個面板,如下所示。選擇要生成的代碼的格式,按OK,這時它已經把生成的代碼複製在你的粘貼板中,然後你在使用這個佈局文件的Activity或Fragment中,按Ctrl + V 把代碼粘貼出來就可以了。
2. SelectorChapek for Android
這是用於生成Selector的插件。你需要在drawable文件夾中右鍵,在彈出的菜單中選擇Generate Android Selectors,如下所示,它就會根據你的幾個drawable文件夾裏的資源的命名,幫你生成Selector代碼。當然,你的資源文件需要根據約定的後綴來命名。比如按下狀態爲_pressed,正常狀態爲_normal,不可用狀態爲_disable,等等。更詳細的說明可以看Github上該項目的說明文件,項目地址爲:https://github.com/inmite/android-selector-chapek。
3. AndroidCodeGenerator
它的介紹說是可以生成ViewHolder和findView方法的代碼。不過怎麼生成findView方法的代碼我還沒找到,但生成ViewHolder也是挺酷炫的。
在你的Adapter實現類的getView當中,將光標定位到你的佈局文件的ID的變量中,按Alt+Insert插件代碼,可以看到多了一項Create view holder,如下圖。
選擇它之後,它會根據佈局文件裏的聲明瞭id的元素,爲你生成對應的ViewHolder代碼,如下所示:
- public class ViewHolder {
- public final TextView time;
- public final ImageView isnew;
- public final TextView username;
- public final TextView department;
- public final ImageView enter;
- public final CircleImageView avatar;
- public final RelativeLayout listcontent;
- public final View root;
- public ViewHolder(View root) {
- time = (TextView) root.findViewById(R.id.time);
- isnew = (ImageView) root.findViewById(R.id.is_new);
- username = (TextView) root.findViewById(R.id.username);
- department = (TextView) root.findViewById(R.id.department);
- enter = (ImageView) root.findViewById(R.id.enter);
- avatar = (CircleImageView) root.findViewById(R.id.avatar);
- listcontent = (RelativeLayout) root.findViewById(R.id.list_content);
- this.root = root;
- }
- }