Reprint: Http://www.jianshu.com/p/e7ba4884dcddBaseItemLayout profile
Some of the following layouts are often encountered at work, marked red:
05.png
07.png
08.png
As a result, a generic item layout is customized so that you can add as many item as you want in just a few lines of code.
Use
<com.maimlandroid:id= "@+id/layout" Android:layout_width= "match_parent" Android:layout_ Height= "wrap_content" app:text_size = "app:text_color" = Span class= "hljs-string" > "@color/gray_333333" app:icon_margin_left = "ten" app:item_height = Span class= "hljs-string" > "app:line_color" = "@color/line_d6d6d6" > </ Com.maiml.library.baseitemlayout>
Layout = (baseitemlayout) Findviewbyid (r.id.layout); List<string> valueList =New Arraylist<> (); Valuelist.add ("album"); Valuelist.add ("Collection"); Valuelist.add ("Purse"); Valuelist.add ("Card package"); Valuelist.add ("Settings"); 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) //text list. Setresidlist (residlist) //icon list setarrowresid (r.drawable.img_find_arrow) // Arrow on the right. Setarrowisshow (true) //whether the right arrow is displayed. Setitemmargintop ( Span class= "Hljs-number" >10) //set the item margin (all). Setitemmargintop ( 0,0) //set the margin for an item. Seticonheight (24) //the height of the icon. Seticonwidth (24" //the width of the icon. Create ();
- Setting Up Listener Events
layout.setOnBaseItemClick(new BaseItemLayout.OnBaseItemClick() { @Override public void onItemClick(int position) { Log.e(TAG,"----- position = " + position); } });
Parameter description
| name |
format |
Description |
| Text_size |
Integer |
Font size |
| Text_color |
Color |
Font Color |
| Icon_margin_left |
Integer |
The margin of the icon from the left |
| Icon_text_margin |
Integer |
Margin to the left of the text distance icon |
| Arrow_margin_right |
Integer |
Arrow from margin to right |
| Item_height |
Integer |
Height of item |
| Line_color |
Color |
The color of the line |
Parametric plots
10.png Source Code
GitHub
2.Android Custom Generic Item layout