我显示了一个带数据的TableLayout,第一行是列的名称,由于第二行是数据,我需要固定第一行,但是必须水平滚动而不是垂直滚动数据(其他行) ,但数据(其他行)仅是数据,必须同时(水平和垂直)都存在,因为ai需要始终查看列的名称。
我将我的餐桌布置成这样:
TableLayout table= (TableLayout) findViewById(R.id.table);
//columns' name (first row)
TableRow column= new TableRow(this);
for(int i=0;i<lenght; i++){
TextView columnName = new TextView(this);
columnName.setText("Column "+i);
column.addView(columnName);
}
table.addView(column); //with this i add the first row with columns' name
//Data
for(int i=0;i<lenght; i++){
TableRow rowData = new TableRow(this);
TextView data= new TextView(this);
data.setText("data "+i);
rowData .addView(data);
table.addView(rowData );//add rows(since the second row)
}
通过这种结构,我可以滚动所有的表格布局:
->ScrollView
->HorizontalScrollView
->TableLayout
答案 0 :(得分:0)
我修复了标题:
<HorizontalScrollView>
<TableLayout>
<TableRow>
<TableLayout>
<--! Headers -->
</TableLayout>
</TableRow>
<TableRow>
<ScrollView>
<TableLayout>
<--! Rows/Data -->
</TableLayout>
</ScrollView>
</TableRow>
</TableLayout>
</HorizontalScrollView>
很显然,如果要使其动态,则必须执行相同的操作,但要编程。 像这样
Your xml:
<HorizonalScrollView>
<TableLayout
android:"@+id/tableMaster">
</TableLayout>
</HorizonalScrollView>
-------------------------------------------------------------------------------------
Your jave code:
//it contains the TablesLayout
TableLayout tableFirst = (TableLayout) findViewById(R.id.tableMaster);
TableRow row1 = new TableRow(this);
TableRow row2 = new TableRow(this);
//The Header
TableLayout tableSecond = new TableLayout(this);
TableRow rowHeader = new TableRow(this);
tableSecond.addView(rowHeader);
//The Data
ScrollView scroll = new ScrollView(this);//It makes this table scrollable vertically
TableLayout tableThird = new TableLayout(this);
TableRow rowData = new TableRow(this);
tableThird.addView(rowData);
scroll.addView(tableThird);
//Add the header
row1.addView(tableSecond);
tableFirst.addView(row1);
//Add the data scrollable
row2.addView(scroll);
tableFirst.addView(row2);
您必须提出自己的逻辑。