标签:pre fill res span name virgo 资源 author enum
好多日子没有写安卓了,今天继续我未完毕的安卓项目。今天主要实现星座展示的12宫格效果。
找好12星座的图片。參见project代码以下的res/drawable文件夹
package com.liuc.constatntEnum; import com.liuc.R; /** * 星座枚举 * * @author Administrator * */ public enum ConstellationEnum { // 星座编号(參数说明 // 0:白羊座、1:金牛座、2:双子座、3:巨蟹座、4:狮子座、 // 5:处女座、6:天秤座、7:天蝎座、8:射手座、9:魔羯座、 // 10:水瓶座、11:双鱼座) Aries(0, "白羊座",R.drawable.aries), Taurus(1, "金牛座",R.drawable.taurus), Gemini(2, "双子座",R.drawable.gemini), Cancer(3, "巨蟹座",R.drawable.cancer), Leo(4, " 狮子座",R.drawable.leo), Virgo(5, "处女座",R.drawable.virgo), Libra(6, "天秤座",R.drawable.libra), Scorpio(7, "天蝎座",R.drawable.scorpio), Sagittarius(8, "射手座",R.drawable.sagittarius), Capricorn(9, "摩羯座",R.drawable.capricorn), Aquarius(10, "水瓶座",R.drawable.aquarius), Pisces(11,"双鱼座",R.drawable.pisces); private ConstellationEnum(int constellationID, String name,int imageID) { this.constellationID = constellationID; this.name = name; this.imageID=imageID; } private int constellationID;//星座ID private String name;//星座名称 private int imageID;//星座图像资源的ID public int getImageID() { return imageID; } public int getConstellationID() { return constellationID; } public String getName() { return name; } }
<?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:orientation="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>
<?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>
/** * 载入主页面12星座布局 */ 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 }); //加入Item到网格中 gridview.setAdapter(adapter); //加入点击事件 gridview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } }); }至此一个12宫格的布局就完毕了。
标签:pre fill res span name virgo 资源 author enum
原文地址:http://www.cnblogs.com/wzjhoutai/p/6891577.html