Android GridView简单实例

Android GridView简单实例,第1张

概述也是今天用到的一个东西,就是简单实现九宫格的Demo1.就是定义各种layout和对应的item

也是今天用到的一个东西,就是简单实现九宫格的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简单实例全部内容,希望文章能够帮你解决Android GridView简单实例所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1147092.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存