简体   繁体   English

如何在Android中创建SpreadSheet类型的显示?

[英]How to create a SpreadSheet kind of display in Android?

我试图在android应用程序中显示一个具有可调整列的SpreadSheet,并且每个列都应该由行包围。我使用了表格布局,数据以表格格式显示,但是我不知道如何用行将每个列包围起来,自动调整。如果有人知道,请帮助我。

You can set a background color for the TableLayout and give your TableRow sa margin: 您可以为TableLayout设置背景颜色,并为TableRow边距:

<TableLayout android:background="#000000">
    <TableRow android:background="#ffffff" android:layout_margin="3dip">
    <!-- etc. -->

I have found this article with a Spreadsheet layout example. 我发现本文带有电子表格布局示例。 Maybe it can be helpful to someone too. 也许对某人也有帮助。 But it is just an example, still need to update it for general purpose. 但这只是一个示例,仍然需要出于一般目的对其进行更新。

http://www.codeofaninja.com/2013/08/android-scroll-table-fixed-header-column.html http://www.codeofaninja.com/2013/08/android-scroll-table-fixed-header-column.html

I open-sourced an elementary spreadsheet I wrote here: 我开源了在这里编写的基本电子表格的来源:

https://github.com/dennis-sheil/android-spreadsheet https://github.com/dennis-sheil/android-spreadsheet

One elementary features it does not have yet: 它尚不具备的一项基本功能:

You can load Microsoft Excel pre-2007 (.xls) files, but not Excel 2007/2010 (.xlsx) files. 您可以加载Microsoft Excel 2007之前(.xls)文件,但不能加载Excel 2007/2010(.xlsx)文件。 This is the feature I have been stuck on implementing for a while. 这是我坚持实施一段时间的功能。 There is a codebase (POI) out there to do this, but there are complexities to implementing it. 有一个代码库(POI)可以做到这一点,但是实现它很复杂。

Use TableLayout.LayoutParams or TableRow.LayoutParams . 使用TableLayout.LayoutParamsTableRow.LayoutParams They inherit ViewGroup.MarginLayoutParams , which you seem to need. 它们继承了您似乎需要的ViewGroup.MarginLayoutParams

A sample code with TableRow.LayoutParams could be: TableRow.LayoutParams的示例代码可能是:

// you can also init values for width, height and weight here
TableRow.LayoutParams params = new TableRow.LayoutParams();
params.setMargins(LEFT_MARGIN, TOP_MARGIN, RIGHT_MARGIN, BOTTOM_MARGIN);

TextView textView = new TextView(this);
textView.setText("I'm in the table");

TableRow row = new TableRow();
row.addView(textView, params);

The same principle could be applied with TableLayout.LayoutParams, when you add to the table layout. 当您添加到表布局时,TableLayout.LayoutParams可以应用相同的原理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM