第一部分 自定义PieView
public class PieChartView extends View {
//定义多种颜色供使用
private int arcColos [] = new int []{getResources().getColor(R.color.gold ), getResources().getColor(R.color.greenyellow )
, getResources().getColor(R.color.lightgreen ), getResources().getColor(R.color.dodgerblue )
, getResources().getColor(R.color.freshgreen ), getResources().getColor(R.color.lightskyblue )};
private final static String TAG = "PieChartView" ;
private List<PieMember> data = null;
//圆心位置
private int centerX , centerY = 0 ;
//整个饼图的半径
private float radius = 200 ;
//中间原型半径
private float hollowRadius = 0 ;
//饼图边距
private float margin = 0 ;
//饼图名称
private String pieName = "" ;
//lable高度
private int lableHeight = 80 ;
private float fontSize = 0 ;
private Paint bgPaint = null;
private Paint arcPaint = null;
private Paint textPaint = null;
public PieChartView (Context context) {
super (context);
this .init();
}
public PieChartView (Context context, AttributeSet attrs) {
super (context, attrs);
this .init();
}
public PieChartView (Context context, AttributeSet attrs, int defStyle) {
super (context, attrs, defStyle);
this .init();
}
public void setPieName (String pieName) {
this .pieName = pieName;
postInvalidate();
}
private void init () {
this .bgPaint = new Paint();
bgPaint .setAntiAlias(true );
this .bgPaint .setColor(getResources().getColor(R.color.theme_main_blue ));
this .bgPaint .setStyle(Paint.Style.FILL_AND_STROKE );
this .arcPaint = new Paint();
this .arcPaint .setAntiAlias(true );
this .arcPaint .setStyle(Paint.Style.FILL_AND_STROKE );
this .textPaint = new Paint();
this .textPaint .setColor(getResources().getColor(R.color.black_overlay ));
this .textPaint .setAntiAlias(true );