簡體   English   中英

Android中具有多個按鈕的自定義圈子

[英]Custom circle with multiple buttons in Android

我是一個嶄新的android開發人員。 我想知道如何繪制帶有厚邊界環的空心圓並將選項嵌入到厚邊界中。 選項的數量取決於用戶選擇的數量(1-10)。 不過,我不知道如何跟蹤屏幕上的信息,如在邊界明確的選項坐標。

也請您告訴我,將來我該如何解決這些自定義查詢,因為文檔僅用於基本參考。

謝謝

圓圈示例 (選項數不是靜態的而是可變的) 在此處輸入圖片說明

使用帶有坐標的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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM