动态设置view的padding和margin值

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);
 

你可能感兴趣的:(padding)