imageView = new ImageView(this); LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(20,20); p.setMargins(10, 0, 0, 0); imageView.setLayoutParams(p);