10633

setting margin of a TableRow issue

Question:

I have the following code, which tries to set the margin:

TableRow tr = new TableRow(this); TableLayout.LayoutParams tableRowParams= new TableLayout.LayoutParams (TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT); int leftMargin=20; int topMargin=50; int rightMargin=0; int bottomMargin=50; tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin); tr.setLayoutParams(tableRowParams); TextView name = new TextView(this); name.setText(Html.fromHtml(venues.get(j).name + "<br><br>" + venues.get(j).getFullAddress()));

However this doesn't set the margin. What am I doing wrong here?

Answer1:

Edit. Whoops, my bad, TableLayout.LayoutParams is fine. Use TableRow.LayoutParams on the children of the TableRow.

I just ran this code (which is, for the most part, your code) and the margin sets correctly

TableRow tr = new TableRow(this); TableLayout.LayoutParams tableRowParams= new TableLayout.LayoutParams (TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT); int leftMargin=100; int topMargin=50; int rightMargin=0; int bottomMargin=50; tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin); tr.setLayoutParams(tableRowParams); TextView tv = new TextView(this); tv.setText("EXAMPLE ROW"); TableRow.LayoutParams textParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); tv.setLayoutParams(textParams); tr.addView(tv); tlayout.addView(tr);

Answer2:

isn't it like so?

TableRow tr = new TableRow(Activity.this)

And I thik you'll nee a table for that row too.

Why not go for XML ?

<TableRow android:id="@+id/tr1" android:layout_width="wrap_content" android:layout_height="wrap_content"> </TableRow>

Recommend

  • How to set background color to entire page in iReport?
  • Jasper iReport table returns an empty document although query works
  • How to embed fonts into a PDF with TCPDF?
  • Place two ImageViews programmatically
  • How to set textfield when the parameter list more than one
  • Adding new page in itextsharp will overlap with header
  • JasperReports: JRDataSource.subDataSource shows undefined
  • how to set marginBottom in android listview or linearlayout Dynamically?
  • Differences between: myView.getLayoutParams().height = screenHeight and myView.setLayoutParams(lp)?
  • Add the flashlight button above the Zxing Scanner page
  • Draw a TextView inside a custom activity?
  • Custom ScaleAnimation / applytransformation is not called
  • Textview values does not update when data received from Arduino
  • Slide image from left to right and right to left
  • Why is this code not working? Hangman
  • Why does PHP appear to evaluate this condition incorrectly?
  • Why does .addView throw this parent/child exception?
  • How to Handle Click on Imageview in Custom Listview with image and Textview?
  • Contact form problem - I do receive messages, but no contents (blank page)
  • UIScrollView setContentOffset: animated: not working
  • Null ImageView Reference
  • QLineEdit password safety
  • Cannot Parse HTML Data Using Android / JSOUP
  • Proper way to use connect-multiparty with express.js?
  • Load html files in TinyMce
  • Trying to get generic when generic is not available
  • Getting Messege Twice Using IMvxMessenger
  • Change div Background jquery
  • How to get Windows thread pool to call class member function?
  • Bitwise OR returns boolean when one of operands is nil
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • JaxB to read class hierarchy
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • To Get the radio button value in ruby on rails