星空网 > 软件开发 > 操作系统

安卓gridview 网格,多行多列实现


Activity()


private int[] image = { R.drawable.camera, R.drawable.wifi, R.drawable.temperature, R.drawable.lamp, R.drawable.wechat, R.drawable.mic, }; private String[] text = { "摄像头", "网络", "温湿度", "电器", "微信", "语音" };

 //显示GridView的界面        GridView gridview = (GridView) findViewById(R.id.gridView1);        ArrayList<HashMap<String, Object>> imagelist = new ArrayList<HashMap<String, Object>>();        // 使用HashMap将图片添加到一个数组中,注意一定要是HashMap<String,Object>类型的,因为装到map中的图片要是资源ID,而不是图片本身         // 如果是用findViewById(R.drawable.image)这样把真正的图片取出来了,放到map中是无法正常显示的        for (int i = 0; i < 6; i++) {          HashMap<String, Object> map = new HashMap<String, Object>();          map.put("image", image[i]);          map.put("text", text[i]);          imagelist.add(map);        }     http://www.cnblogs.com/xiaobo-Linux/ qq463431476        SimpleAdapter simpleAdapter = new SimpleAdapter(this, imagelist,           R.layout.items, new String[] { "image", "text" }, new int[] {               R.id.image, R.id.title });        // 设置GridView的适配器为新建的simpleAdapter       gridview.setAdapter(simpleAdapter);


  <GridLayout      android:layout_width="match_parent"      android:layout_height="83dp"      android:columnCount="1"     >    </GridLayout>    <GridView      android:id="@+id/gridView1"      android:layout_width="match_parent"      android:layout_height="53dp"      android:layout_gravity="left|bottom"      android:columnWidth="90dp"      android:fadeScrollbars="true"       android:numColumns="2"      android:stretchMode="columnWidth" />

items.

<?  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical" >  <ImageView    android:id="@+id/image"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:paddingLeft="10px"    android:scaleType="fitCenter" />  <TextView    android:id="@+id/title"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_gravity="center"    android:padding="5px" /></LinearLayout>

 

安卓中的GridView属性大全

android:numColumns=”auto_fit” //GridView的列数设置为自动 android:columnWidth=”90dp " //每列的宽度,也就是Item的宽度 android:stretchMode=”columnWidth" //缩放与列宽大小同步 android:verticalSpacing=”10dp” //两行之间的边距 android:horizontalSpacing=”10dp” //两列之间的边距 android:cacheColorHint="#00000000" //去除拖动时默认的黑色背景 android:listSelector="#00000000" //去除选中时的黄色底色 android:scrollbars="none" //隐藏GridView的滚动条 android:fadeScrollbars="true" //设置为true就可以实现滚动条的自动隐藏和显示 android:fastScrollEnabled="true" //GridView出现快速滚动的按钮(至少滚动4页才会显示) android:fadingEdge="none" //GridView衰落(褪去)边缘颜色为空,缺省值是vertical。(可以理解为上下边缘的提示色) android:fadingEdgeLength="10dip" //定义的衰落(褪去)边缘的长度 android:stackFromBottom="true" //设置为true时,你做好的列表就会显示你列表的最下面 android:transcriptMode="alwaysScroll" //当你动态添加数据时,列表将自动往下滚动最新的条目可以自动滚动到可视范围内 android:drawSelectorOnTop="false" //点击某条记录不放,颜色会在记录的后面成为背景色,内容的文字可见(缺省为false)



原标题:安卓gridview 网格,多行多列实现

关键词:GridView

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

WE海外仓:https://www.goluckyvip.com/tag/9205.html
罗马尼亚海运:https://www.goluckyvip.com/tag/92050.html
海运罗马尼亚:https://www.goluckyvip.com/tag/92051.html
去菲律宾海运:https://www.goluckyvip.com/tag/92052.html
发新西兰海运:https://www.goluckyvip.com/tag/92053.html
至新西兰海运:https://www.goluckyvip.com/tag/92054.html
去日本入住酒店,东西随意用却有一个特殊“要:https://www.vstour.cn/a/411241.html
中国有哪些著名的酒店品牌。:https://www.vstour.cn/a/411242.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流