RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( new LayoutParams(100,LayoutParams.FILL_PARENT)); ivTabNow.setBackgroundColor(getResources().getColor(R.color.bg)); params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);// 居于屏幕中间 ly.addView(ivTabNow, params);