menu.setNumColumns(5);// 设置每行列数 menu.setGravity(Gravity.CENTER);// 位置居中 menu.setVerticalSpacing(10);// 垂直间隔 menu.setHorizontalSpacing(10);// 水平间隔 menu.setAdapter(getMenuAdapter(a)); menu.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub switch (arg2) { case 0: break; case 1: break; case 2: break; case 3: break; case 4: break; } } }); }
?
private ListAdapter getMenuAdapter(String[] a2) { // TODO Auto-generated method stub ArrayList<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>(); for (int i = 0; i < a2.length; i++) { HashMap<String, Object> map = new HashMap<String, Object>(); map.put("itemText", a2[i]); data.add(map); } SimpleAdapter simperAdapter = new SimpleAdapter(this, data, R.layout.item, new String[] { "itemText" }, new int[] { R.id.item_text }); return simperAdapter; }
?
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/RelativeLayout_Item" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="5dip"> <TextView android:id="@+id/item_text" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFFFFFFF"></TextView></RelativeLayout>
?