The TableModel determines how legend items are organized into a grid. All TableModel implementations use a TableOrder to decide how items are populated:
TableOrder.ROW_MAJOR: Items are added left-to-right, then top-down.TableOrder.COLUMN_MAJOR: Items are added top-down, then left-to-right.
Androidplot provides two primary implementations:
DynamicTableModel
Subdivides the LegendWidget's visible space into a fixed number of rows and columns. Use this when you want the legend to fill a specific grid shape regardless of pixel size.
FixedTableModel
Uses a fixed pixel size for each cell. It automatically wraps items to the next row or column when the available space is exceeded.
Note: When using pixel values, it is recommended to use PixelUtils.dpToPix() to ensure consistent sizing across different screen densities.
// Example: 2x2 grid using ROW_MAJOR
plot.getLegend().setTableModel(new DynamicTableModel(2, 2, TableOrder.ROW_MAJOR));
// Example: Fixed cell size (300w x 100h) using COLUMN_MAJOR
plot.getLegend().setTableModel(new FixedTableModel(
PixelUtils.dpToPix(300),
PixelUtils.dpToPix(100),
TableOrder.COLUMN_MAJOR
));