2.Android 自訂通用的Item布局

來源:互聯網
上載者:User

標籤:android   item   int   lis   script   pac   drawable   end   original   

轉載:http://www.jianshu.com/p/e7ba4884dcddBaseItemLayout簡介

在工作中經常會遇到下面的一些布局,標紅處:


05.png
07.png
08.png

因此自訂了一個通用的Item布局,只需幾行代碼就可以根據需要添加任意個item。

使用
  • 添加Gradle依賴

    在 build.gradle 的 dependencies 添加

      dependencies {       ...       compile ‘com.maiml:baseitemlayoutlibrary:1.0.0‘  }
  • 在布局使用
 <com.maiml.library.BaseItemLayout         android:id="@+id/layout"         android:layout_width="match_parent"         android:layout_height="wrap_content"         app:text_size  = "15"         app:text_color = "@color/gray_333333"         app:icon_margin_left = "10"         app:icon_text_margin = "10"         app:arrow_margin_right = "10"         app:item_height = "50"         app:line_color = "@color/line_d6d6d6"         >     </com.maiml.library.BaseItemLayout>
  • 代碼中調用
 layout = (BaseItemLayout) findViewById(R.id.layout); List<String> valueList = new ArrayList<>();        valueList.add("相簿");        valueList.add("收藏");        valueList.add("錢包");        valueList.add("卡包");        valueList.add("設定");        List<Integer> resIdList = new ArrayList<>();        resIdList.add(R.drawable.xc);        resIdList.add(R.drawable.sc);        resIdList.add(R.drawable.qb);        resIdList.add(R.drawable.kb);        resIdList.add(R.drawable.sz);        layout.setValueList(valueList) // 文字 list              .setResIdList(resIdList) // icon list              .setArrowResId(R.drawable.img_find_arrow) // 右邊的箭頭              .setArrowIsShow(true) //是否顯示右邊的箭頭              .setItemMarginTop(10)  //設定 item的邊距(全部)              .setItemMarginTop(0,0) // 設定 某一個item 的邊距              .setIconHeight(24)    // icon 的高度              .setIconWidth(24)      // icon 的寬度             .create();
  • 設定監聽事件
    layout.setOnBaseItemClick(new BaseItemLayout.OnBaseItemClick() {            @Override            public void onItemClick(int position) {                Log.e(TAG,"----- position = " + position);            }        });
參數說明
name format description
text_size integer 字型大小
text_color color 字型顏色
icon_margin_left integer 表徵圖距離 左邊的margin
icon_text_margin integer 文字距離 表徵圖左邊的margin
arrow_margin_right integer 箭頭距離右邊的margin
item_height integer item的高度
line_color color 線的顏色
參數圖解
10.png源碼

GitHub

2.Android 自訂通用的Item布局

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.