You need to use the TableRow.LayoutParams
, since your adding the ImageView
into a TableRow
Change the LayoutParams
as
TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.MATCH_PARENT);
lp.setMargins(10, 10, 10,10);
imgLove.setLayoutParams(lp);
If ImageView
is added to a RelativeLayout
then use RelativeLayout.LayoutParams
If ImageView
is added to a LinearLayout
then use LinearLayout.LayoutParams