上回再写了《Android中使用ListView绘制自定义表格》后,很多人留言代码不全和没有数据样例。但因为项目原因,没法把源码全部贴上来。近两天,抽空简化了一下,做了一个例子。

效果图如


一、功能:

     1、支持列合并

     2、考虑了界面刷新优化

     3、预留部分接口

     4、支持左右滚动

1、枚举类:CellTypeEnum

package csdn.danielinbiti.custometableview.item;public enum CellTypeEnum {  STRING   //字符 ,DIGIT   //数字  ,LABEL   //标签}
该类定义了表格支持的样式,可以根据需要扩充,扩充了新类型,注意同时修改CustomeTableItem中新类型样式的创建方式


2、核心代码CustomeTableItem,该类对应ListView的一行item。类支持列合并,没有实现行合并(行合并样式控制上会比较复杂些,如有需要自己改写吧)

rowtype:该值主要表示表格中不同行的样式,如果合并的列都一样的行,则可以复用,不需要再创建了。

package csdn.danielinbiti.custometableview.item;import java.util.ArrayList;import csdn.danielinbiti.custometableview.R;import android.content.Context;import android.util.AttributeSet;import android.view.LayoutInflater;import android.view.View;import android.widget.EditText;import android.widget.LinearLayout;import android.widget.TextView;import android.widget.LinearLayout.LayoutParams;public class CustomeTableItem extends LinearLayout {private Context context = null;private boolean isRead = false;//是否只读private ArrayList viewList = new ArrayList();//行的表格列表private int[] headWidthArr = null;//表头的列宽设置private String rowType = "0";//行的样式idpublic CustomeTableItem(Context context) {super(context);}public CustomeTableItem(Context context, AttributeSet attrs) {super(context, attrs);}public CustomeTableItem(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);}/* * rowType:行的样式,字符任意,相同样式的行不需要再创建了 * itemCells:单元格信息 * headWidthArr:每列宽度 * isRead:是否只读,如果是只读,则所有的输入都不生效 */    public void buildItem(Context context,String rowType,ArrayList itemCells    ,int[] headWidthArr,boolean isRead){this.setOrientation(LinearLayout.VERTICAL);//第一层布局垂直    this.context = context;    this.headWidthArr =headWidthArr.clone();        this.rowType = rowType;            this.addCell(itemCells);    }    private void addCell(ArrayList itemCells){    this.removeAllViews();    LinearLayout secondLayout = new LinearLayout(context);secondLayout.setOrientation(LinearLayout.HORIZONTAL);secondLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));this.addView(secondLayout);    int cellIndex = 0;    for(int i=0;i itemCells){for(int i=0;i


源码下载地址点击打开链接







更多相关文章

  1. TextView详解一
  2. 布局概述之帧布局FrameLayout和布局概述之表格布局TableLayout
  3. Android(安卓)ProgressBar 自定义样式(一)
  4. Android表格布局之设置边框
  5. android屏幕适配建议 (二)
  6. android之样式和主题
  7. Android绘制竖直虚线完美解决方案—自定义View
  8. Android拼接合并图片生成长图
  9. Android:样式和主题

随机推荐

  1. Activity 属性设置大全
  2. SubscriptionController
  3. android内嵌H5页面
  4. Android常用控件之ExpandableList的使用
  5. 获取Android设备的方向
  6. android之interpolator的用法详解
  7. [置顶] android studio 使用checkstyle全
  8. 彻底解决Android(安卓)应用方法数不能超
  9. iOS和Android的兼容 (一)
  10. Android(安卓)4.0 开发者指南(27) —— R