A lot of days did not write Android, today continue my unfinished Android project. Today the main realization of the constellation display of the 12-lattice effect.
1. Constellation Pictures
Find a picture of the 12 constellation, see the Res/drawable directory below the engineering code
2, Constellation enumeration class is necessary to build this enumeration class, can make our code clearer, while avoiding the situation of magic numbers. The code for the enumeration class is as follows:
Package Com.liuc.constatntenum;import com.liuc.r;/** * Constellation Enumeration * * @author Administrator * */public enum Constellationenum {//Constellation number (parameter description///0: Aries, 1: Taurus, 2: Gemini, 3: Cancer, 4: Leo,//5: Virgo, 6: Libra, 7: Scorpio, 8: Sagittarius, 9: Capricorn,//10: Aquarius, 11: Pisces) Aries (0, "Aries", r.drawable.aries), Taurus (1, "Taurus", R.drawable.taurus), Gemini (2, "Gemini", R.drawable.gemini), Cancer (3, "cancer", R.drawable.cancer), Leo (4, "Leo", R.drawable.leo), Virgo (5, "Virgo", R.drawable.virgo), Libra (6, "Libra", R.drawable.libra) , Scorpio (7, "Scorpio", R.drawable.scorpio), Sagittarius (8, "Sagittarius", R.drawable.sagittarius), Capricorn (9, "Capricorn", R.drawable.capricorn), Aquarius (10, "Aquarius", R.drawable.aquarius), Pisces (11, "Pisces", r.drawable.pisces);p rivate Constellationenum (int constellationid, String name,int imageID) {This.constellationid = Constellationid;this.name = Name;this.imageid=imageid;} private int constellationid;//constellation Idprivate String name;//constellation name private int imageid;//constellation Image Resource Idpublic int Getimageid () { return ImageID;} public int Getconstellationid () {return constellationid;}public String GetName () {return name;}} 3, the main interface 12 Palace layout using the GridView as a container, each grid using Imageview+textview display mode to show the main interface layout:
<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" match_parent " android:o rientation= "vertical" > <gridview android:id= "@+id/constellation_gridview" android:layout_ Width= "Fill_parent" android:layout_height= "fill_parent" android:numcolumns= "3" android:columnwidth = "90DP" android:stretchmode= "columnWidth" android:gravity= "center" > </GridView> </RelativeLayout>
Layout xml for each lattice:
<?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=" wrap_content " > < ImageView android:id= "@+id/imageview" android:layout_width= "wrap_content" android:layout_height= " Wrap_content " android:layout_centerhorizontal=" true " /> <textview android:id=" @+id/item _text " android:layout_width=" wrap_content " android:layout_height=" wrap_content " android:layout_ Centerhorizontal= "true" android:layout_below= "@+id/imageview" /></relativelayout>
4. Mainactivity Initial layout effect
/** * Load Main Page 12 constellation layout */private void Loadtwelveconstellation () {GridView GridView = (GridView) This.findviewbyid ( R.id.constellation_gridview); list<map<string, object>> list = new arraylist<map<string, object>> (); For (Constellationenum constellation:ConstellationEnum.values ()) {map<string, object> Map = new hashmap< String, object> (); Map.put ("Itemimage", Constellation.getimageid ()); Map.put ("Itemtext", Constellation.getname ()); List.add (map); } simpleadapter adapter = new Simpleadapter (this, list,r.layout.itemmenu, new string[] {"Itemimage", "Itemtext"}, New int[] {r.id.imageview, r.id.item_text}); Add item to Grid in Gridview.setadapter (adapter); Add Click event Gridview.setonitemclicklistener (New Onitemclicklistener () {@Overridepublic void Onitemclick (adapterview< ;? > Parent, View view,int position, long ID) {}});At this point a 12 Gongge layout is complete. The interface effect is as follows: I three mobile phone test, 5.1 inch screen can be full screen display, two 4.3 screen will appear scroll bar ... The screen-based adaptive display will be modified in the final version of the code
code Address: http://download.csdn.net/detail/shanhuhau/8065877
Android project Development Combat (2)--Constellation show 12 Palace lattice