Answer the question
In order to leave comments, you need to log in
Android development: draw a table with scrolling vertically and horizontally?
There is a task: to draw a table based on a two-dimensional list, the table should automatically adjust to the size of the text in the cells. The table may not fit on the screen, it must be scrollable vertically and horizontally.
So far, it turned out to be written like this (in the cycle I go through the columns, inside each column in the cycle I go through the cells):
LinearLayout table = new LinearLayout(this);
table.setOrientation(LinearLayout.HORIZONTAL);
for (LevelColumn level : statistics.levels) {
LinearLayout column = new LinearLayout(this);
column.setOrientation(LinearLayout.VERTICAL);
TextView header = new TextView(this);
header.setText(level.name);
column.addView(header);
for (Score score : level.scores) {
TextView cell = new TextView(this);
cell.setText(score.teamName);
column.addView(cell);
}
table.addView(column);
}
TwoDScrollView scrollView = new TwoDScrollView(this);
scrollView.addView(table);
setContentView(scrollView);
Answer the question
In order to leave comments, you need to log in
Perhaps this will help:
If it does not help, then for the cell, similarly specify the wrap content parameter.
LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
column.setLayoutParams(params);
you can make your own custom view and use canvas
Sorry, but I give the code in c #
Use commands like
A to find out the size of the text, like this:
Rect bounds = new Rect();
p.GetTextBounds (text, 0, text.Length, bounds);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question