轉載:http://www.jianshu.com/p/e7ba4884dcdd
BaseItemLayout
簡介
在工作中經常會遇到下面的一些布局,如圖標紅處:

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