更新:すべて完了です!LinearLayoutには、実際の高さと幅が必要でした。私はそれらを追加する必要はないと確信していますが、少なくともそれは私に何かをするための何かを与えてくれます。タ。私はこれに自己回答したでしょうが、どうやら評判が十分ではなく、8時間待つ必要があります。私はこれを整理し、質問を投稿し、2時間で解決するために何日も費やしました。ソズ。
私は何か間違ったことをしていると思います。私はいくつかの例を見て、ほとんど同じことをしていると思いましたが、明らかにそうではありませんでした。
更新:指摘しておくべきことですが、私はaChartEngineグラフライブラリを使用してPieChartViewをLinearLayoutに追加しています
方法があります
protected DefaultRenderer buildCategoryRenderer(int[] colors) {
if(renderer==null)
renderer = new DefaultRenderer();
renderer.setClickEnabled(true);
renderer.setZoomEnabled(true);
renderer.setSelectableBuffer(10);
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.argb(100, 50, 50, 50));
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(15);
renderer.setLegendTextSize(15);
renderer.setMargins(new int[] { 20, 30, 15, 0 });
renderer.setZoomButtonsVisible(true);
renderer.setStartAngle(90);
for (int color : colors) {
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(color);
renderer.addSeriesRenderer(r);
}
return renderer;
}
これはonCreate()で次のように呼び出されます
MyDataSource dataSource = new MyDataSource(this);
dataSource.open();
dataSet = new CategorySeries("Analysis");
int i = 0;
for(String category:categoriesArray){
dataSet.add(category, dataSource.getTotalForCategory(category).getNumbers().doubleValue());
colors[i]=listOfColours[i];
i++;
}
dataSource.close();
buildCategoryRenderer(colors);
次にonResume()で
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
if(graph==null){
graph = ChartFactory.getPieChartView(this, dataSet, renderer);
LinearLayout graphLayout = (LinearLayout)findViewById(R.id.all_graph);
graphLayout.addView(graph, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
}else{
graph.repaint();
}
}
これは私のxmlレイアウトです
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" android:scrollbars="vertical">
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/summary_table" >
<LinearLayout android:id="@+id/all_graph"
android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1">
</LinearLayout>
<LinearLayout android:background="@android:drawable/list_selector_background" android:id="@+id/current_foo_row">
<TextView
android:id="@+id/foos_current_foo"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_marginTop="25dp"
android:layout_marginLeft="10dp"
android:text="@string/current"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium"
android:textStyle="bold"
/>
<TextView
android:id="@+id/current_foo_value"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_marginTop="25dp"
android:layout_weight="0.4"
style="@android:style/TextAppearance.Holo.Medium"
android:textStyle="bold"/>
<ImageView
android:layout_width="0px"
android:layout_height="fill_parent"
android:src="@android:drawable/ic_menu_more"
android:contentDescription="@string/more"
android:layout_weight="0.1"/>
</LinearLayout>
<!-- Hidden bar in/Spend -->
<LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:visibility="gone" android:background="@drawable/back" android:id="@+id/bar_spend_row" style="@android:style/TextAppearance.DeviceDefault.Medium">
<TextView
android:id="@+id/bar_spend"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:text="@string/bar_spend"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium.Inverse"
/>
<TextView
android:id="@+id/bar_spend_value"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium.Inverse"/>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:visibility="gone" android:background="@drawable/back" android:id="@+id/bar_in_row" style="@android:style/TextAppearance.DeviceDefault.Medium">
<TextView
android:id="@+id/bar_in"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:text="@string/bar_in"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium.Inverse"/>
<TextView
android:id="@+id/bar_in_value"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium.Inverse"/>
</LinearLayout>
<!-- FINISH -->
<LinearLayout android:background="@android:drawable/list_selector_background" android:id="@+id/maybe_foo_row" style="@android:style/TextAppearance.DeviceDefault.Medium">
<TextView
android:id="@+id/foos_month_expected_foo"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_marginTop="25dp"
android:layout_marginLeft="10dp"
android:text="@string/expected"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium"
android:textStyle="bold"
/>
<TextView
android:id="@+id/maybe_foo_value"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_marginTop="25dp"
android:layout_weight="0.4"
style="@android:style/TextAppearance.Holo.Medium"
android:textStyle="bold"/>
<ImageView
android:layout_width="0px"
android:layout_height="fill_parent"
android:src="@android:drawable/ic_menu_more"
android:contentDescription="@string/more"
android:layout_weight="0.1"/>
</LinearLayout>
<!-- Hidden bar in/Spend -->
<LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:visibility="gone" android:background="@drawable/back" android:id="@+id/remaining_spend_row" style="@android:style/TextAppearance.DeviceDefault.Medium">
<TextView
android:id="@+id/remaining_spend"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:text="@string/remaining_spend"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium.Inverse"/>
<TextView
android:id="@+id/remaining_spend_value"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium.Inverse"/>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="0px" android:visibility="gone" android:background="@drawable/back" android:id="@+id/remaining_in_row" style="@android:style/TextAppearance.DeviceDefault.Medium">
<TextView
android:id="@+id/remaining_in"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:text="@string/remaining_in"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium.Inverse"/>
<TextView
android:id="@+id/remaining_in_value"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="0.50"
style="@android:style/TextAppearance.Holo.Medium.Inverse"/>
</LinearLayout>
<!-- FINISH -->
<LinearLayout >
<Button
android:id="@+id/foos_add_transaction_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:text="@string/add_transaction"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
</TableLayout>
その結果、チャートは表示されません。何か案は?