GridView的基本使用
来源:互联网 发布:手机指画软件 编辑:程序博客网 时间:2024/06/06 16:36
GridView是一个表格视图,应用在表格的布局里面非常的方面,基本简单的应用代码如下:
下面的是item的布局
效果图:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.aeckj.distribution.MainActivity" android:orientation="horizontal" > <TextView android:id="@+id/tv_address" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:background="#A7FA17" /> <ImageView android:id="@+id/imageview" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center"/> </LinearLayout>
主页面的布局:
<LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="2" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="我的规划:"/> android:id="@+id/sv_myPlan" android:layout_width="match_parent" android:layout_height="wrap_content"> --> <GridView android:id="@+id/gv_parent" android:layout_width="fill_parent" android:layout_height="wrap_content" android:columnWidth="20dp" android:verticalSpacing="20dp"android:horizontalSpacing="20dp" android:numColumns="3" android:gravity="center" > </GridView><pre name="code" class="html"> </LinearLayout>
</pre><pre code_snippet_id="1718721" snippet_file_name="blog_20160616_4_9675646" name="code" class="html">执行代码:
<pre name="code" class="java"> private String[] itemTexts = new String[] { "北京市东城区港澳中心AAAAAA", "北京市东城区东四十条港澳中心203", "北京市东城区东四十条港澳中心204", "北京市东城区东四十条港澳中心205", "北京市东城区东四十条港澳中心206", "北京市东城区东四十条港澳中心207", "北京市东城区东四十条港澳中心208", "北京市东城区东四十条港澳中心209" }; private int[] itemImages = new int[] { R.drawable.enter, R.drawable.enter, R.drawable.enter, R.drawable.enter, R.drawable.enter, R.drawable.enter, R.drawable.enter, R.drawable.enter };/* (non-Javadoc) * @see android.app.Activity#onCreate(android.os.Bundle) */@SuppressLint("NewApi")@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_path_planning);lv_panning = (ListView) findViewById(R.id.lv_panning);//sv_myPlan = (ScrollView) findViewById(R.id.sv_myPlan);gv_parent = (GridView) findViewById(R.id.gv_parent);adapterGraid= new MyGridViewAdapter(this);gv_parent.setAdapter(getAdapter()); } private ListAdapter getAdapter() { Log.e("set adapter", "set adapter====jss"); List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>(); for (int i = 0; i < itemTexts.length; i++) { HashMap<String, Object> map = new HashMap<String, Object>(); map.put("itemText", itemTexts[i]); list.add(map); map.put("itemImage", itemImages[i]); } // 该构造函数,这里说明一下 // 第一个参数为new SimpleAdapter(Context, 上面的list,每一个项对应的itemView,itemView里显示的所有信息(要和list里的map里的名称一样) , // itemView里控件id); SimpleAdapter simpleAdapter = new SimpleAdapter(this, list, R.layout.item_path_plan, new String[] { "itemText" ,"itemImage" }, new int[] { R.id.tv_address ,R.id.imageview }); return simpleAdapter; }}
0 0
- GridView的基本使用
- 2.7 GridView的基本使用
- Android RecyclerView 的基本使用之GridView
- GridView(网络视图)的基本使用
- gridview 基本使用
- GridView的基本操作
- Gridview的基本用法
- GridView的基本使用方法
- GridView的基本应用
- GridView的基本用法
- GridView的使用
- GridView的使用
- gridview的详细使用
- GridView的使用
- GridView的使用技巧.
- 学习gridview的使用
- GridView表头的使用
- GridView的使用
- 关于九度OJ 1202问题的再讨论
- log4j保留某段时间内的日志
- HTTP协议详解(真的很经典)
- Reids Cluster 部署
- Web后端 之 PHP 编程工程化手段
- GridView的基本使用
- python的命令行参数处理
- 190. Reverse Bits
- 百度地图的使用定位,逆地理编码,自定义不同类型的大头针
- android 删除sd卡某个目录下的所有文件
- 牛客网刷题笔记---求最短未排序子序列
- Oracle 多表查询
- eclipse使用MAVEN打包可执行的jar包
- 命令行学习