GridView 弄的 StringGrid

news/2024/7/4 12:56:00

1、

主界面 layout_main.xml :

 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     xmlns:tools="http://schemas.android.com/tools"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:paddingBottom="@dimen/activity_vertical_margin"
 6     android:paddingLeft="@dimen/activity_horizontal_margin"
 7     android:paddingRight="@dimen/activity_horizontal_margin"
 8     android:paddingTop="@dimen/activity_vertical_margin"
 9     tools:context="z.stringgridandroidz.MainActivity" >
10 
11     <HorizontalScrollView
12         android:id="@+id/horizontalScrollView1"
13         android:layout_width="wrap_content"
14         android:layout_height="wrap_content"
15         android:layout_alignParentBottom="true"
16         android:layout_alignParentLeft="true"
17         android:layout_alignParentRight="true"
18         android:layout_alignParentTop="true" >
19 
20         <LinearLayout
21             android:layout_width="match_parent"
22             android:layout_height="match_parent"
23             android:orientation="vertical" >
24 
25             <GridView android:id="@+id/gridView1"
26                 android:layout_height="wrap_content" 
27                 android:layout_width="match_parent" 
28                 android:numColumns="5">
29             </GridView>
30 
31         </LinearLayout>
32     </HorizontalScrollView>
33 </RelativeLayout>

 

ZC:<LinearLayout/> 和 <HorizontalScrollView/> 是一起的,界面上也就一个 <GridView/>...

 

2、

在 res-->layout 中添加一个 items.xml 用于每个GridView单元格的样式,内容为:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout android:id="@+id/LinearLayout01"
 3     xmlns:android="http://schemas.android.com/apk/res/android"
 4     android:layout_width="fill_parent" android:background="#555555"
 5     android:layout_height="wrap_content">
 6     <TextView android:layout_below="@+id/ItemImage" android:text="TextView01"
 7         android:id="@+id/ItemText" android:bufferType="normal"
 8         android:singleLine="true" android:background="#FFFFFF"
 9         android:layout_width="fill_parent" android:gravity="center"
10         android:layout_margin="1dip" android:layout_gravity="center"
11         android:layout_height="wrap_content">
12     </TextView>
13 </LinearLayout>

 

3、

测试代码:

 1 package z.stringgridandroidz;
 2 
 3 import java.util.ArrayList;
 4 import java.util.HashMap;
 5 
 6 import android.app.Activity;
 7 import android.os.Bundle;
 8 import android.widget.GridView;
 9 import android.widget.LinearLayout;
10 import android.widget.SimpleAdapter;
11 
12 public class MainActivity extends Activity {
13 
14     @Override
15     protected void onCreate(Bundle savedInstanceState)
16     {
17         super.onCreate(savedInstanceState);
18         setContentView(R.layout.activity_main);
19         
20     // ***
21         
22         // 数据源
23         ArrayList<HashMap<String, String>> dateSource = new ArrayList<HashMap<String, String>>();
24         // 向数据源中添加数据
25         for (int i = 0; i < 1600; i++)
26         {
27             HashMap<String, String> map = new HashMap<String, String>();
28             map.put("ItemText", Integer.toString(i)+"_123456789");
29             dateSource.add(map);
30         }
31         
32         // Adapter
33         SimpleAdapter simpleAdapter = new SimpleAdapter(MainActivity.this,
34                 dateSource,// 数据来源
35                 R.layout.items,//XML实现
36                 new String[] { "ItemText" },// 动态数组与ImageItem对应的子项
37                 new int[] { R.id.ItemText });
38  
39         GridView gv = (GridView) this.findViewById(R.id.gridView1);  
40         gv.setAdapter(simpleAdapter);
41         
42         LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(  
43                 800, LinearLayout.LayoutParams.WRAP_CONTENT);  
44         gv.setLayoutParams(params);
45         
46         simpleAdapter.notifyDataSetChanged();
47     }
48 
49 }

 

4、

缺点:

4.1、

GridView 的宽度,需要自己在程序里面设置:

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( 800, LinearLayout.LayoutParams.WRAP_CONTENT );
gv.setLayoutParams(params);

 

4.2、

GridView 默认的 垂直的滚动条是在最右边的...

需要将 GridView 翻到最右边才能看到垂直的滚动条...

 

 

 

 

 

X

 

转载于:https://www.cnblogs.com/codeskilla/p/4955942.html


http://www.niftyadmin.cn/n/3095327.html

相关文章

zabbix3.0配置邮件报警

我们部署一套监控软件&#xff0c;报警这一块自然不可或缺&#xff0c;接下来我们看看zabbix如何实现邮件报警。1、编写发送邮件的脚本zabbix通脚本发送邮件&#xff0c;遵循的传参格式为&#xff1a;脚本 收件人 标题 邮件内容先来看看脚本&#xff08;sendmail_zabbix.py…

mac 键盘使用

2019独角兽企业重金招聘Python工程师标准>>> 1)按 delete 键&#xff0c;实现 Windows 键盘上退格键的功能&#xff0c;也就是删除光标之前的一个字符&#xff08;默认&#xff09;&#xff1b; 2)按 fndelete 键&#xff0c;删除光标之后的一个字符&#xff1b; 3)…

Windows与centos,centos与centos互传文件

Windows与centos相互传文件 要有个工具PentestBox&#xff08;很强大&#xff09;下面是下载链接 链接&#xff1a;https://pan.baidu.com/s/1CF7HzjiGi3wnpScphJoF3g 提取码&#xff1a;hvfm 复制这段内容后打开百度网盘手机App&#xff0c;操作更方便哦 安装如下(安…

Provisioning Services 7.8 入门系列教程之一 部署学习环境介绍

首次接触Provisioning Services时&#xff0c;让笔者想起了以前。不知是一九九几年&#xff0c;笔者已记不清。那时&#xff0c;个人电脑还很贵。为了节约成本&#xff0c;好多局域网采取无盘工作站。记得当时使用是Novell的NetWare 3.12&#xff0c;当时还是用的DOS。当时&…

centos7装docker

Docker是什么&#xff1a; Docker是一个开源的应用容器引擎&#xff0c;Docker可以让开发者打包应用及依赖包到一个轻量级、可移植的容器中&#xff0c;然后发布到任何Linux上运行&#xff0c;容器是完全沙箱机制&#xff0c;相互间不会有任何接口&#xff0c;而且容器性能开销…

连连看的原生JS实现V2

对上一次的连连看程序进行了一点修改&#xff1a; 1 var llk function () {2 this.ReStart();3 }4 llk.prototype {5 Init: function () {6 //初始化游戏界面7 for (var i 0; i < 5; i) {8 …

用Windows的cmd也能给centos互传文件了

用Windows自带的cmd&#xff0c;cmd查看文件不是ls&#xff0c;是dir 要安装一个小的应用putty&#xff0c;下载链接如下&#xff08;64位的&#xff09; 链接&#xff1a;https://pan.baidu.com/s/1R5iPPJy_dziTUNYq3vSYeA 提取码&#xff1a;mcof 复制这段内容后打开百度网…

Qt出现QObject::connect: Cannot queue arguments of type '******'的解决方法

一般出现这种情况都是自定义的类型进行型号槽连接的时候出现的&#xff0c;使用 假设自定义的类型是MyClass 使用qRegisterMetaType<MyClass>("MyClass");注册之后就可以正常的进行信号和槽连接 转载于:https://www.cnblogs.com/-wang-cheng/p/4962257.html