1、动态设置padding,拿ImageView为例
ImageView imageView = new ImageView(Context context);
imageView.setPadding(left,top,right,bottom);
2、动态设置margin,拿LinearLayout里边放ImageVIew为例
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(20, 20);
params.setMargins(20, 0, 20, 0);
imageView.setLayoutParams(params);
3、动态设置TextView drawLeft drawRight
Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_new);
rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight());
textview.setCompoundDrawables(null, null, rightDrawable, null);