在android4.0以上版本中,新增加了GridLayout网格布局,请参考Android 4.0开发之GridLayOut布局实践和浅谈android4.0开发之GridLayout布局

<?xml version="1.0" encoding="utf-8"?> <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_gravity="center"    android:columnCount="4"//该网格布局有4列    android:orientation="horizontal" > //水平依次排列,排满4列后,换行排列    <Button        android:layout_column="3"//该按钮定位在第4列上(从0开始计算)        android:text="/" />     <Button android:text="1" />     <Button android:text="2" />     <Button android:text="3" />     <Button android:text="*" />     <Button android:text="4" />     <Button android:text="5" />     <Button android:text="6" />     <Button android:text="-" />     <Button android:text="7" />     <Button android:text="8" />     <Button android:text="9" />     <Button        android:layout_rowSpan="3"//该按钮在一列上占3行        android:layout_gravity="fill"//该按钮填充占满一列3行        android:text="+" />     <Button        android:layout_columnSpan="2"//该按钮在一行上占2列        android:layout_gravity="fill"        android:text="0" />     <Button android:text="00" />     <Button        android:layout_columnSpan="3"        android:layout_gravity="fill"        android:text="=" /> </GridLayout>
效果图:



在开发中有些时候完成某些功能,不得不在java代码中实现GridLayout

java代码:

GridLayout.LayoutParams gllpTv;gllpTv = new GridLayout.LayoutParams();gllpTv.columnSpec = GridLayout.spec(0, 5);//相当于android:layout_columnSpan="5" spec(start,size)参数为起始位置,占几列TextView timeText = new TextView(this);timeText.setText("********");timeText.setTextSize(26);timeText.setPadding(10, 50, 0, 5);gridlayout.addView(timeText, gllpTv);//把控件和布局参数添加到GridLayout

类似Gridview的使用

for (int j = 0; j < playRecordList.size(); j++) {        View v = inflater.inflate(R.layout.gridview_playrecord_item_layout, null);ImageView playrecord_img = (ImageView) v.findViewById(R.id.play_record_img);        TextView playrecord_name = (TextView) v.findViewById(R.id.play_record_name);fb.display(playrecord_img, playRecordList.get(j).getVideoImgUrl());playrecord_name.setText(playRecordList.get(j).getVideoName());playrecord_img.setFocusable(true);playrecord_img.setClickable(true);playrecord_img.setTag(playRecordList.get(j));playrecord_img.setOnClickListener(myCliclListener);gridlayout.addView(v);}


还在继续更新中!!!






更多相关文章

  1. Android控件(View)之TextView, Button, ImageButton, ImageView,
  2. Android学习系列一用按钮实现显示时间
  3. Android布局整合include界面控件
  4. Android-Fragment
  5. Android沉浸式状态栏设计的实例代码
  6. Android(安卓)Fragment 详细翻译
  7. Android---3---布局之LinearLayout
  8. Android开发笔记(一百二十)两种侧滑布局
  9. Android精通:TableLayout布局,GridLayout网格布局,FrameLayout帧布

随机推荐

  1. mysql innodb的监控(系统层,数据库层)
  2. 详解mysql基本操作语句命令
  3. MySql服务未知原因消失解决方法
  4. CentOS下RPM方式安装MySQL5.6教程
  5. DROP TABLE在不同数据库中的写法整理
  6. MySQL thread_stack连接线程的优化
  7. MYSQL 解锁与锁表介绍
  8. Navicat中导入mysql大数据时出错解决方法
  9. mysql 导出CSV文件 并带表头的方法
  10. mysql导出查询结果到csv的实现方法