简体   繁体   中英

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 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

I open-sourced an elementary spreadsheet I wrote here:

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. 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.

Use TableLayout.LayoutParams or TableRow.LayoutParams . They inherit ViewGroup.MarginLayoutParams , which you seem to need.

A sample code with TableRow.LayoutParams could be:

// 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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