Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 1.45 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Android: Lining up Views in TableRow programatically
  2. <ScrollView
  3.   android:id="@+id/countEditList"
  4.   android:layout_width="match_parent"
  5.   android:layout_height="wrap_content">
  6.   <TableLayout
  7.     android:id="@+id/countEditLayout"
  8.     android:stretchColumns="*"
  9.     android:gravity="center"
  10.     android:layout_width="fill_parent"
  11.     android:layout_height="fill_parent">
  12.    <!-- insert the new rows here as they are created -->
  13.   </TableLayout>
  14. </ScrollView>
  15.        
  16. TableRow row = new TableRow(this);
  17.  
  18. EditText title = new EditText(this);
  19. title.setHorizontallyScrolling(true);
  20. title.setGravity(Gravity.CENTER);
  21. title.setLayoutParams(new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  22.  
  23. EditText counting = new EditText(this);
  24. counting.setLayoutParams(new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  25. counting.setGravity(Gravity.CENTER);
  26.  
  27. Button deleteCount = new Button(this);
  28. deleteCount.setLayoutParams(new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  29. deleteCount.setText(R.string.deleteCount);
  30. deleteCount.setOnClickListener(this);
  31. deleteCount.setGravity(Gravity.CENTER);
  32.  
  33. row.addView(title);
  34. row.addView(counting);
  35. row.addView(deleteCount);
  36. layout.addView(row,new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); // Earlier: layout = (ViewGroup) findViewById(R.id.countEditLayout);
  37.        
  38. title.setPadding(3, 3, 3, 3);
  39. counting.setPadding(3, 3, 3, 3);