Dynamically set the padding and margin values of the view Dynamically set the padding and margin values of the view

1. Dynamically set padding, take ImageView as an example:

 

Java code Favorite code
  1. ImageViewimageView=newImageView(Contextcontext);
  2. imageView.setPadding(left,top,right,bottom);

2. Dynamically set margin

Take the ImageVIew example in LinearLayout

 

Java code Favorite code
  1. LinearLayout.LayoutParamsparams=newLinearLayout.LayoutParams(20,20);
  2. params.setMargins(20,0,20,0);
  3. imageView.setLayoutParams(params);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326510146&siteId=291194637