Creación de un TableView con una fila de encabezado fijo (no se desplaza)

Tengo un TableView llamado aTable. InitialiseDTable () agrega la primera fila con un fondo ROJO

GOL

  1. Evite que la fila del encabezado se desplace ( TRABAJO FINO )

  2. Mantenga la fila del encabezado con el mismo ancho de cada TextView que da la sensación de que es el hijo de aTable ( NOT WORKING )

ATTEMP

Mi intento fue crear un tableview antes de la scrollview y poblar aTable luego extraer la fila de encabezado e insertar como un niño de este tableview.

CÓDIGO PARA AÑADIR LA RUTA DEL CABEZAL A LA MESA

public void initialiseDTable() { LayoutInflater inflater = getLayoutInflater(); TableRow row = (TableRow) inflater.inflate(R.layout.table_row, dTable, false); View v = (View) inflater.inflate(R.layout.table_cell, row, false); TextView A = (TextView) v.findViewById(R.id.table_cell_text); A.setText(tag1); row.addView(v); v = (View) inflater.inflate(R.layout.table_cell, row, false); A = (TextView) v.findViewById(R.id.table_cell_text); A.setText(tag2); row.addView(v); v = (View) inflater.inflate(R.layout.table_cell, row, false); A = (TextView) v.findViewById(R.id.table_cell_text); A.setText(tag3); row.addView(v); v = (View) inflater.inflate(R.layout.table_cell, row, false); A = (TextView) v.findViewById(R.id.table_cell_text); A.setText(tag4); row.addView(v); if (this.showEST) { v = (View) inflater.inflate(R.layout.table_cell, row, false); A = (TextView) v.findViewById(R.id.table_cell_text); A.setBackgroundColor(Color.RED); A.setText(tag5); row.addView(v); } dTable.addView(row); } 

CÓDIGO

 public void updateATable() { aTable.removeAllViews(); initialiseATable(); for (int i = 0; i < newA.size(); i++) aTable.addView(newA.get(i)); //newA is an ArrayList <TableRow> View view = aTable.getChildAt(0); aTable.removeViewAt(0); aTableH.removeAllViews(); aTableH.addView(view,new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); } 

XML

  <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:id="@+id/aLL"> <TableLayout android:shrinkColumns="5" android:stretchColumns="1,2,3,4" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/aTableH"> </TableLayout> <ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/aTableSV"> <TableLayout android:shrinkColumns="5" android:stretchColumns="1,2,3,4" android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/aTable"> </TableLayout> </ScrollView> </LinearLayout> 

Estoy escribiendo una serie de artículos que cubren este preciso número. El primero está aquí y describe un enfoque similar a la respuesta ya dada. Sin embargo, los próximos dos artículos cubren una solución mucho más elegante.

FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.