动态设置控件边距

ImageView mImageButton = (ImageView)findViewById(R.id.xxx);


相对布局中:

RelativeLayout.LayoutParams myButtonParams = (RelativeLayout.LayoutParams) mImageButton.getLayoutParams();

myButtonParams.rightMargin = 120;

线性布局中:

LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mImageButton.getLayoutParams();

lp.leftMargin = 120;


mImageButton.setLayoutParams(myButtonParams);//(lp);

你可能感兴趣的:(动态设置控件边距)