public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.table_layout);
TableRow.LayoutParams wrapWrapTableRowParams = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
int[] fixedColumnWidths = new int[]{20, 20, 20, 20, 20};
int[] scrollableColumnWidths = new int[]{20, 20, 20, 30, 30};
int fixedRowHeight = 50;
int fixedHeaderHeight = 60;
TableRow row = new TableRow(this);
TableLayout header = (TableLayout) findViewById(R.id.table_header);
row.setLayoutParams(wrapWrapTableRowParams);
row.setGravity(Gravity.CENTER);
row.setBackgroundColor(Color.YELLOW);
row.addView(makeTableRowWithText("col 1", fixedColumnWidths[0], fixedHeaderHeight));
row.addView(makeTableRowWithText("col 2", fixedColumnWidths[1], fixedHeaderHeight));
row.addView(makeTableRowWithText("col 3", fixedColumnWidths[2], fixedHeaderHeight));
row.addView(makeTableRowWithText("col 4", fixedColumnWidths[3], fixedHeaderHeight));
row.addView(makeTableRowWithText("col 5", fixedColumnWidths[4], fixedHeaderHeight));
header.addView(row);
TableLayout fixedColumn = (TableLayout) findViewById(R.id.fixed_column);
TableLayout scrollablePart = (TableLayout) findViewById(R.id.scrollable_part);
for(int i = 0; i < 10; i++) {
TextView fixedView = makeTableRowWithText("row number " + i, scrollableColumnWidths[0], fixedRowHeight);
fixedView.setBackgroundColor(Color.BLUE);
fixedColumn.addView(fixedView);
row = new TableRow(this);
row.setLayoutParams(wrapWrapTableRowParams);
row.setGravity(Gravity.CENTER);
row.setBackgroundColor(Color.WHITE);
row.addView(makeTableRowWithText("value 2", scrollableColumnWidths[1], fixedRowHeight));
row.addView(makeTableRowWithText("value 3", scrollableColumnWidths[2], fixedRowHeight));
row.addView(makeTableRowWithText("value 4", scrollableColumnWidths[3], fixedRowHeight));
row.addView(makeTableRowWithText("value 5", scrollableColumnWidths[4], fixedRowHeight));
scrollablePart.addView(row);
}
}
private TextView recyclableTextView;
public TextView makeTableRowWithText(String text, int widthInPercentOfScreenWidth, int fixedHeightInPixels) {
int screenWidth = getResources().getDisplayMetrics().widthPixels;
recyclableTextView = new TextView(this);
recyclableTextView.setText(text);
recyclableTextView.setTextColor(Color.BLACK);
recyclableTextView.setTextSize(20);
recyclableTextView.setWidth(widthInPercentOfScreenWidth * screenWidth / 100);
recyclableTextView.setHeight(fixedHeightInPixels);
return recyclableTextView;
}
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:id="@+id/fillable_area">
<TableLayout
android:id="@+id/table_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:id="@+id/fillable_area">
<TableLayout
android:id="@+id/fixed_column"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout
android:id="@+id/scrollable_part"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
</LinearLayout>
分享到:
相关推荐
在网页上实现类似Excel的效果,数据滚动条拖动固定第一行和第一列,附代码备注,一目了然
表格固定左序列、顶部序列、第一行、列标题、统计行; 自动统计,排序(自定义统计规则); 表格图文、序列号、列标题格式化; 表格各组成背景、文字、网格、padding等配置; 表格批注; 表格内容、列标题点击事件;...
javascript 绘制表格table,可以固定首行,首列,其他内容滚动显示.兼容ie,firefox,chrome等浏览器.
表格固定左序列、顶部序列、第一行、列标题、统计行; 自动统计,排序(自定义统计规则); 表格图文、序列号、列标题格式化; 表格各组成背景、文字、网格、padding等配置; 表格批注; 表格内容、列标题点击事件;...
表格固定左序列、顶部序列、第一行、列标题、统计行; 自动统计,排序(自定义统计规则); 表格图文、序列号、列标题格式化; 表格各组成背景、文字、网格、padding等配置; 表格批注; 表格内容、列标题点击事件;...
1.表格的宽度以及表格每一列的宽度需要固定(特殊情况除外:当表格列数少并且表格总宽度明显小于表格父容器的宽度时,也就是表格列不存在自动换行的问题) 2.表格父容器尺寸大小改变时,需要调用 setBoxSize 方法,...
修改高级表格支持库,在双击单元格进入编辑状态后,不能收到第一个“字符输入”事件的BUG。 2. OpenGL支持库中的部分英文名称常量已改为中文,并统一在所有常量名称之前加前缀“GL_”,以减少与其它库的冲突机率。...
附详细使用说明,非常简单,解决问题直接了当。
1.表格的宽度以及表格每一列的宽度需要固定(特殊情况除外:当表格列数少并且表格总宽度明显小于表格父容器的宽度时,也就是表格列不存在自动换行的问题) 2.表格父容器尺寸大小改变时,需要调用 setBoxSize 方法,...
horizontal_data_table Flutter Widget,用于创建水平表,左侧固定列。安装该程序包开始支持声音为零的安全性。 尽管该软件包是手动迁移的,并已通过每个功能进行了测试,但如果集成/迁移存在任何问题,请随时在...
目录回到顶部↑第一部分 tcl基础 第1章 tcl的基本概念 1.1 tcl命令 1.2 hello,world! 1.3 变量 1.4 命令替代 1.5 数学表达式 1.6 反斜杠替代 1.7 花括号和双引号的组合 1.8 过程 1.9 阶乘举例 ...
包含如下关键特性:重做了工具栏图标,优化了插入表格交互体验,现在点击表格图标按钮,弹出行列选择面板,滑动鼠标选择要插入的表格行数和列数即可实现表格快速插入,插入表格后,光标会自动置于第一个单元格内;...
作为一种脚本语言,Tcl与其他的Unix shell语言,如Bourne Shell(sh)、C Shell(csh)、Korn Shell以及Perl类似。Shell程序可以让你执行其他的程序。它们提供了足够的可编程特性(变量、流程控制和过程),使你可以将现有...
Web标准和ASP.NET - 第一部分 XHTML介绍 在ASP.NET页面中推荐使用覆写(Override)而不是事件处理(Event Handler) 常用编码工具类,支持base64,md5,des,crc32 也谈谈技术面试 在C#里把ArrayList转换为Array 或 把...
第1章 Java语言的GUI历史 2 1.1 最初的AWT 2 1.2 Swing工具包 3 1.3 Eclipse的诞生 3 1.4 Eclipse贡献SWT工具包 5 1.4.1 SWT的结构 6 1.4.2 SWT所支持的操作系统 6 1.5 Sun AWT/Swing与Eclipse SWT 7 ...