• 安卓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);


    主xml

        <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.xml

    <?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: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)
  • 相关阅读:
    Yarn下分片和分块源代码分析
    Yarn下Map数控制
    hadoop中使用的Unsafe.java
    hbase的coprocessor使用(转)
    eclipse插件
    短线及时发现个股机会的七大招数
    hadoop分类输出
    安装ubuntu-tweak
    rabbitmq安装使用
    “-Xmx1024m -Xms1024m -Xmn512m -Xss256k”——Java运行参数(转)
  • 原文地址:https://www.cnblogs.com/zhaocundang/p/5529821.html
Copyright © 2020-2023  润新知