0

I have a table layout where each row is built programmatically.

The structure is basically, for each row:

TextView, LinearLayout, LinearLayout, LinearLayout, Button.

Each of the LinearLayout has multiple ImageViews inside of them. I want to increase the spacing between the ImageView items as they render with their borders touching.

I tried the suggestions here - In Android, how to make space between LinearLayout children? - I create the parameters like so:

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.WrapContent);

And set it like this to an image view when adding the control:

linearLayout1.AddView(image1);
linearLayout1.AddView(image2, layoutParams);
linearLayout1.AddView(image3);

Note I am only setting it on the middle item as a left & right margin on this would be fine for what I am trying to achieve.

The problem is that even without setting any margins on the layout params i.e. just instantiating it and setting it as shown above, it adds about a 35px margin to the left causing a much larger margin than I wanted. Even calling SetMargins with 1px doesn't change the margin.

Where am I going wrong?

Community
  • 1
  • 1
Sam
  • 4,219
  • 7
  • 52
  • 80

1 Answers1

0

set width of linear layout as WrapContent like this

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);
Dhruvil Patel
  • 2,910
  • 2
  • 22
  • 39