答案 0 :(得分:0)
您可以使用以下代码创建水平饼图。
您可以为表格行提供百分比。
TableRow row = new TableRow(this); TableRow.LayoutParams params1 = new TableRow.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT,10f); row.setLayoutParams(params1); row.setPadding(50,10,50,10); // row.setBackgroundColor(Color.parseColor("#22000000"));
TextView tv = new TextView(this);
TableRow.LayoutParams params2 = new TableRow.LayoutParams(0, 110, 50f);
tv.setLayoutParams(params2);
tv.setTextSize(30);
tv.setBackgroundResource(R.drawable.green_chart);
// tv.setBackgroundColor(Color.parseColor("#659D32"));
TextView tv2 = new TextView(this);
TableRow.LayoutParams params3 = new TableRow.LayoutParams(0, TableLayout.LayoutParams.MATCH_PARENT, 10f);
tv2.setLayoutParams(params3);
tv2.setBackgroundColor(Color.parseColor("#ffff19"));
TextView tv3 = new TextView(this);
TableRow.LayoutParams params4 = new TableRow.LayoutParams(0, TableLayout.LayoutParams.MATCH_PARENT, 40f);
tv3.setLayoutParams(params4);
tv3.setBackgroundResource(R.drawable.red_chart);
//tv3.setBackgroundColor(Color.parseColor("#FF0000"));
row.addView(tv);
row.addView(tv2);
row.addView(tv3);
通过使用此代码,您将获得如图所示的精确图表。