代码实现 layout_marginLeft 与 centerParent 等

LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(left, top, right, bottom);
imageView.setLayoutParams(lp);

  RelativeLayout.LayoutParams rel_btn = new RelativeLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
  rel_btn.height = 60;
  rel_btn.width = 60;
  BtnNext.setLayoutParams(rel_btn);

 rel_btn.addRule(RelativeLayout.CENTER_VERTICAL);
 rel_btn.leftMargin = 220;

转贴:http://stackoverflow.com/questions/4044563/android-programatically-layout-a-button-view

你可能感兴趣的:(layout)