Document directory
- First Effect
- The following are specific implementations:
First Effect
Supplement: Download specific applications: Android Market
Problem 1: When you bind data with SimpleAdapter, the image must be in front of the Item, and the text must be in the back
Unknown reason
Question 2: Select "yes" in "set Item", which includes the green background of some systems.
Set the color of listSelector in the GridView to be consistent with that in the background.
The following are specific implementations:
1 Interface
<GridView android:listSelector="#FAF4FF" android:id="@+id/GridView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:columnWidth="140dp" android:padding="0dp" android:numColumns="2" android:stretchMode="columnWidth" > </GridView>
Griditem Interface
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:background="@drawable/itemselect"android:layout_height="wrap_content"android:padding="10dp"><ImageView android:layout_width="130dp" android:background="@drawable/imgbar" android:id="@+id/ItemImage" android:adjustViewBounds="true" android:padding="1dp" android:layout_height="108dp" android:layout_centerHorizontal="true"/><TextView android:layout_width="wrap_content" android:layout_height="27dp" android:layout_marginBottom="10dp" android:layout_below="@+id/ItemImage" android:textColor="#000000" android:textSize="19sp" android:id="@+id/ItemText" android:layout_centerHorizontal="true"/></RelativeLayout>
Bind background data:
ArrayList <HashMap <String, Object> meumList = new ArrayList <HashMap <String, Object> (); HashMap map = new HashMap <String, Object> (); map. put ("ItemImage", R. drawable. f11); map. put ("ItemText", "squirrel mandarin fish"); meumList. add (map); SimpleAdapter saItem = new SimpleAdapter (this, meumList, // data source R. layout. griditem, // xml implement new String [] {"ItemImage", "ItemText"}, // corresponding map Key new int [] {R. id. itemImage, R. id. itemText }); // Id of the corresponding R // Add the Item to the grid gridview. setAdapter (saItem); // Add the Click Event gridview. setOnItemClickListener (new OnItemClickListener () {@ Override public void onItemClick (AdapterView <?> Arg0, View arg1, int arg2, long arg3) {Intent intent = new Intent (); intent. putExtra ("index", arg2); intent. setClass (Main. this, Detail. class); startActivity (intent );}});