Android Studio比較常用的幾個插件

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代碼,如下所示:

  1. public class ViewHolder {  
  2.     public final TextView time;  
  3.     public final ImageView isnew;  
  4.     public final TextView username;  
  5.     public final TextView department;  
  6.     public final ImageView enter;  
  7.     public final CircleImageView avatar;  
  8.     public final RelativeLayout listcontent;  
  9.     public final View root;  
  10.   
  11.     public ViewHolder(View root) {  
  12.         time = (TextView) root.findViewById(R.id.time);  
  13.         isnew = (ImageView) root.findViewById(R.id.is_new);  
  14.         username = (TextView) root.findViewById(R.id.username);  
  15.         department = (TextView) root.findViewById(R.id.department);  
  16.         enter = (ImageView) root.findViewById(R.id.enter);  
  17.         avatar = (CircleImageView) root.findViewById(R.id.avatar);  
  18.         listcontent = (RelativeLayout) root.findViewById(R.id.list_content);  
  19.         this.root = root;  
  20.     }  
  21. }  



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章