1、获取按钮的LayoutParams
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)button.getLayoutParams()2、在LayoutParams中设置margin
layoutParams.setMargins(100,20,10,5)//4个参数按顺序分别是左上右下3、把这个LayoutParams设置给按钮
button.setLayoutParams(layoutParams) //mView是控件1、定义LayoutParamsLinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)//定义一个LayoutParams
2、在LayoutParams中设置marginLeft
layoutParams.setMargins(20,0,0,0)//4个参数按顺序分别是左上右下
3、把这个LayoutParams设置给控件
mView.setLayoutParams(layoutParams)//mView是控件
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)