標籤:android item int lis script pac drawable end original
轉載:http://www.jianshu.com/p/e7ba4884dcddBaseItemLayout簡介
在工作中經常會遇到下面的一些布局,標紅處:
05.png
07.png
08.png
因此自訂了一個通用的Item布局,只需幾行代碼就可以根據需要添加任意個item。
使用
<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布局