国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android GridView簡單實例

2019-10-23 19:50:01
字體:
來源:轉載
供稿:網友

也是今天用到的一個東西,就是簡單實現九宮格的Demo

1.就是定義各種layout 和對應的item

我的:

<?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);

最后扔一張效果圖

Android,GridView

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 连山| 珠海市| 喜德县| 达孜县| 通河县| 阳新县| 沽源县| 淳安县| 南安市| 左云县| 独山县| 泉州市| 霍邱县| 巴彦淖尔市| 甘孜县| 吴堡县| 志丹县| 罗田县| 乌拉特后旗| 彩票| 湘潭县| 万源市| 莒南县| 株洲市| 灵宝市| 长岛县| 阳城县| 明光市| 民县| 苍梧县| 六安市| 白银市| 泰顺县| 吉林市| 师宗县| 行唐县| 灵川县| 成武县| 拜城县| 双峰县| 涿鹿县|