解决方法
//ImageView Setup ImageView imageView = new ImageView(this); //setting height and width of imageview LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); //setting margins around imageimageview params.setMargins(10,10,10); //left,top,right,bottom //adding attributes to the imageview imageView.setLayoutParams(params);