I have defined a TableLayout in my Java code. For each row, I'm displaying three ImageButtons. When one of those buttons is pressed, the background color changes. To display it nicely, I have set a padding of 10px.
The problem I'm having now is that if you press two buttons that are next to each other, you don't exactly see a break between the buttons. So I'm wondering, is there a possibility to set a margin on the ImageButtons or an other solution whatshowever?
Try
int leftMargin = 10;
((MarginLayoutParams) imageButton.getLayoutParams()).leftMargin = leftMargin;
EDIT:
If you don't use ImageButton
defined in xml, you have to set LayoutParams
like this:
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params.leftMargin = 10;
b.setLayoutParams(params);
Here I assume you use LinearLayout
in your list item.
Make sure to use to use the LayoutParams
for the container the control is in. In your case the buttons are in a TableRow
so use TableRow.LayoutParams
if you use any other type of params, the control will not show at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With