List (listview), table (gridview), which must be indispensable in mobile apps. How to implement a more complex interface? Let's take a look at my.
This layout is the most basic and commonly used. There are many implementation methods for such a layout on the Internet, but many of them need to implement the adapter by themselves, it seems complicated and unnecessary, because we have simple but not simple simpleadapter.
1. listview
Simpleadapter CoreCode:
For (INT I = 0; I < 10; I ++) {Map < String , Object > Map = new hashmap < String , Object > (); Map. put ("pic", R. drawable. PIC); map. put ("title", "test title"); map. put ("content", "Test content"); contents. add (MAP);} simpleadapter adapter = new simpleadapter (this, (list < Map < String , Object > >) Contents, R. layout. listitem, new string [] {"pic", "title", "content"}, new int [] {R. id. listitem_pic, R. id. listitem_title, R. id. listitem_content}); listview. setadapter (adapter );
Layout of listitem:
<? XML version =" 1.0 "Encoding =" UTF-8 "?> <Relativelayout xmlns: Android ="Http://schemas.android.com/apk/res/android "Android: layout_width =" Fill_parent "Android: layout_height =" ? Android: ATTR/listpreferreditemheight "> <Imageview Android: Id =" @ + ID/listitem_pic "Android: layout_width =" Wrap_content "Android: layout_height =" Fill_parent "Android: layout_alignparenttop =" True "Android: layout_alignparentbottom =" True "Android: src =" @ Drawable/PIC "Android: adjustviewbounds ="True "Android: padding =" 2dip "/> <Textview Android: Id =" @ + ID/listitem_title "Android: layout_width =" Wrap_content "Android: layout_height =" Wrap_content "Android: layout_torightof =" @ + ID/listitem_pic "Android: layout_alignparentright =" True "Android: layout_alignparenttop =" True "Android: layout_above =" @ + ID/listitem_content "Android: layout_alignwithparentifmissing =" True "Android: gravity =" Center_vertical "Android: text =" @ + ID/listitem_title "Android: textsize =" 22px "/> <Textview Android: Id =" @ + ID/listitem_content "Android: layout_width =" Fill_parent "Android: layout_height =" Wrap_content "Android: layout_torightof =" @ + ID/listitem_pic "Android: layout_alignparentbottom =" True "Android: layout_alignparentright =" True "Android: singleline ="True "Android: ellipsize =" Marquee "Android: text =" @ + ID/item_content "Android: textsize =" 14px "/> </Relativelayout>
2. gridview
Simpleadapter core code:
For (INT I = 0; I<10; I ++) {Map<String,Object>Map = new hashmap<String,Object>(); Map. put ("pic", R. drawable. PIC); map. put ("title", "test title"); contents. add (MAP);} simpleadapter adapter = new simpleadapter (this, (list<Map<String,Object>>) Contents, R. layout. griditem, new string [] {"pic", "title"}, new int [] {R. id. griditem_pic, R. id. griditem_title,}); gridview. setadapter (adapter );
Layout of griditem:
<? XML version =" 1.0 "Encoding =" UTF-8 "?> <Linearlayout xmlns: Android =" Http://schemas.android.com/apk/res/android "Android: layout_height =" Fill_parent "Android: layout_width =" Fill_parent "Android: Orientation =" Vertical "> <Imageview Android: Id =" @ + ID/griditem_pic "Android: layout_width =" Wrap_content "Android: layout_height =" Wrap_content "Android: layout_gravity ="Center_horizontal "> </Imageview> <textview Android: Id =" @ + ID/griditem_title "Android: layout_width =" Wrap_content "Android: layout_height =" Wrap_content "Android: layout_gravity =" Center_horizontal "Android: text =" Test "> </Textview> </linearlayout>
Final attachment code: http://files.cnblogs.com/game-over/test.zip