ImageViewで動的にmarginを設定
xmlではなくJavaコードでImageViewの余白を動的に設定する方法。
android - How to set margin of ImageView using code, not xml - Stack Overflow
StackOverflowで解決。
ImageView image_view = ( ImageView )findViewById( R.id.test_image );
// ImageViewの大きさを設定
LinearLayout.LayoutParams layout_params = new LinearLayout.LayoutParams( width, height );
layout_params.setMargins( left, top, right, bottom ); // marginを設ける
image_view.setLayoutParams( layout_params ); // ImageViewのレイアウトを登録