[英]Custom circle with multiple buttons in Android
使用帶有坐標的MappedImage,創建您的mapdimage
你需要用畫布畫圓
public class DountChart extends View {
private int ScrWidth, ScrHeight;
//The percentage of presentation, in actual use, is the external scale parameter
private final float arrPer[] = new float[]{10f, 10f, 10f, 10f, 10f, 10f, 10f, 10f, 10f, 10f};
//RGB array of colors
private final int arrColorRgb[][] = {{77, 83, 97},
{148, 159, 181},
{77, 83, 97},
{148, 159, 181}, {77, 83, 97},
{148, 159, 181}, {77, 83, 97},
{148, 159, 181}, {77, 83, 97},
{148, 159, 181}};
public PanelDountChart2(Context context) {
super(context);
// TODO Auto-generated constructor stub
//The screen information
DisplayMetrics dm = getResources().getDisplayMetrics();
ScrHeight = dm.heightPixels;
ScrWidth = dm.widthPixels;
}
public void onDraw(Canvas canvas) {
//Canvas background
canvas.drawColor(Color.WHITE);
float cirX = ScrWidth / 2;
float cirY = ScrHeight / 3;
float radius = ScrHeight / 5;//150;
float arcLeft = cirX - radius;
float arcTop = cirY - radius;
float arcRight = cirX + radius;
float arcBottom = cirY + radius;
RectF arcRF0 = new RectF(arcLeft, arcTop, arcRight, arcBottom);
//Brush the initialization
Paint PaintArc = new Paint();
Paint PaintLabel = new Paint();
PaintLabel.setColor(Color.WHITE);
PaintLabel.setTextSize(16);
//Position calculation
XChartCalc xcalc = new XChartCalc();
float Percentage = 0.0f;
float CurrPer = 0.0f;
int i = 0;
for (i = 0; i < arrPer.length; i++) {
//The percentage of conversion as a pie chart display angle
Percentage = 360 * (arrPer[i] / 100);
Percentage = (float) (Math.round(Percentage * 100)) / 100;
//The distribution of color
PaintArc.setARGB(255, arrColorRgb[i][0], arrColorRgb[i][1], arrColorRgb[i][2]);
//Display the proportion in a pie chart
canvas.drawArc(arcRF0, CurrPer, Percentage, true, PaintArc);
//Calculating the percentage of label
xcalc.CalcArcEndPointXY(cirX, cirY, radius - radius / 2 / 2, CurrPer + Percentage / 2);
//Identification
canvas.drawText(Float.toString(arrPer[i]) + "%", xcalc.getPosX(), xcalc.getPosY(), PaintLabel);
//The starting point of the next
CurrPer += Percentage;
}
//Painting circle
PaintArc.setColor(Color.WHITE);
canvas.drawCircle(cirX, cirY, radius / 2, PaintArc);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.