private void initActivity() {
FrameLayout content = new FrameLayout(this);
// 圖表顯示范圍在占屏幕大小的90%的區域內
DisplayMetrics dm = getResources().getDisplayMetrics();
int scrWidth = (int) (dm.widthPixels * 0.9);
int scrHeight = (int) (dm.heightPixels * 0.8);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(scrWidth, scrHeight);
// 設置位置
layoutParams.alignWithParent=true;
layoutParams.addRule(RelativeLayout.BELOW ,R.id.liner);
ShenGao.this.addContentView(mCharts[mSelected], layoutParams);
}
R.id.liner是我在xml布局裡寫好的控件,又手動創建了一個組件的,但是手動創建的組件不能居中,求解
lp.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);