1. Dynamically set padding, take ImageView as an example:
- ImageViewimageView=newImageView(Contextcontext);
- imageView.setPadding(left,top,right,bottom);
2. Dynamically set margin
Take the ImageVIew example in LinearLayout
- LinearLayout.LayoutParamsparams=newLinearLayout.LayoutParams(20,20);
- params.setMargins(20,0,20,0);
- imageView.setLayoutParams(params);