在xml里书写控件大小位置时,常常使用dp值,但是,如果在Java代码中书写控件位置:
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);//定义一个LayoutParams
//在LayoutParams中设置marginLeft
layoutParams.setMargins