代码如下:
imageView2=new ImageView(this);
LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams(new Double(width*0.8).intValue(),height/3);
layoutParams.gravity= Gravity.CENTER_HORIZONTAL;
layoutParams.setMargins(5,10,5,10);
imageView2.setLayoutParams(layoutParams);
当然还有SlidingPaneLayout.LayoutParams,ViewGroup.LayoutParams,DrawerLayout.LayoutParams等等,方式一样