
Untitled
By: a guest on
Apr 28th, 2012 | syntax:
None | size: 1.45 KB | hits: 16 | expires: Never
Android: Lining up Views in TableRow programatically
<ScrollView
android:id="@+id/countEditList"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableLayout
android:id="@+id/countEditLayout"
android:stretchColumns="*"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- insert the new rows here as they are created -->
</TableLayout>
</ScrollView>
TableRow row = new TableRow(this);
EditText title = new EditText(this);
title.setHorizontallyScrolling(true);
title.setGravity(Gravity.CENTER);
title.setLayoutParams(new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
EditText counting = new EditText(this);
counting.setLayoutParams(new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
counting.setGravity(Gravity.CENTER);
Button deleteCount = new Button(this);
deleteCount.setLayoutParams(new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
deleteCount.setText(R.string.deleteCount);
deleteCount.setOnClickListener(this);
deleteCount.setGravity(Gravity.CENTER);
row.addView(title);
row.addView(counting);
row.addView(deleteCount);
layout.addView(row,new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); // Earlier: layout = (ViewGroup) findViewById(R.id.countEditLayout);
title.setPadding(3, 3, 3, 3);
counting.setPadding(3, 3, 3, 3);