Android GridView 간단 한 인 스 턴 스

3128 단어 AndroidGridView
오늘 사용 한 것 중 하나 입 니 다.바로 구 궁 격 을 간단하게 실현 하 는 데모 입 니 다.
1.다양한 레이아웃 과 대응 하 는 아 이 템 을 정의 합 니 다.
나의:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="#fff"
  android:orientation="vertical" >

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <GridView 
      android:id="@+id/gridView"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:numColumns="3"
      android:background="#fff"></GridView>


  </LinearLayout>

</LinearLayout>
itme 의

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:padding="10dp"
  android:layout_gravity="center"
  android:background="#fff"
  android:orientation="vertical" >

  <ImageView
    android:id="@+id/iv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

  <TextView
    android:id="@+id/tv"
    android:paddingTop="10dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#000"
    android:text="  " />

</LinearLayout>
데이터 준비 시작:

  /**
   *        
   */
  public void initData() {
    //       ,       ,        
    lstImageItem = new ArrayList<HashMap<String, Object>>();
    for (int i = 0; i < 3; i++) {
      HashMap<String, Object> map = new HashMap<String, Object>();
      map.put("ItemImage", R.drawable.osg);//        ID
      map.put("ItemText", "    " + String.valueOf(i));//     ItemText
      lstImageItem.add(map);
    }
  }

디 스 플레이 설정

gv = (GridView) view.findViewById(R.id.gridView);
    SimpleAdapter adapter = new SimpleAdapter(this, lstImageItem, R.layout.gridview_item, new String[] { "ItemImage", "ItemText" },
        new int[] { R.id.iv, R.id.tv });
gv.setAdapter(adapter);

마지막 으로 효과 도 한 장 던 져 주세요.

이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기