(Android Control) Development Summary of the GridView Control

Source: Internet
Author: User
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 );}});
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.