case R.id.graphs:
GraphicalView mChartView1 = new Niveau().execute(this);
GraphicalView mChartView2 = // another chartView creation
LinearLayout layout = (LinearLayout) findViewById(R.id.graph);
layout.removeAllViews();
layout.addView(mChartView1, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
layout.addView(mChartView2, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
break;
それはうまくいくはずです。必ず異なるIDを使用してください。mChartView
プログラムで作成し、XMLレイアウトから拡張しない場合は、プログラムでIDを設定する必要もあります。
mChartView1.setId(1);
mChartView2.setId(2);
また、RelativeLayout
おそらくレイアウトと配置に関してより多くのカスタマイズを提供します。次に、レイアウトパラメータで相対位置を設定する必要があります。
RelativeLayout layout = (RelativeLayout) findViewById(R.id.graph);
....
RelativeLayout.LayoutParams paramsForChart2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
paramsForChart2.addRule(RelativeLayout.RIGHT_OF, mChartView1.getId());
layout.addView(mChartView2, paramsForChart2);