Android 如何手动绘制饼图?

Android 如何手动绘制饼图?,android,Android,我需要手动绘制饼图。我需要一些基本的想法。有人能帮我吗???是Java中的一个例子(不适用于Android)。通过使用一个代替Graphics2D的对象,您可以轻松地为Android移植它。例如,您可以使用。是Java中的一个示例(不适用于Android)。通过使用一个代替Graphics2D的对象,您可以轻松地为Android移植它。例如,您可以使用。创建您自己的自定义类,并实现onDraw方法来使用绘制图表,而不是使用fillArc 然后,您可以像使用内置组件一样将图表组件包含在布局中。创建

我需要手动绘制饼图。我需要一些基本的想法。有人能帮我吗???

是Java中的一个例子(不适用于Android)。通过使用一个代替Graphics2D的对象,您可以轻松地为Android移植它。例如,您可以使用。

是Java中的一个示例(不适用于Android)。通过使用一个代替Graphics2D的对象,您可以轻松地为Android移植它。例如,您可以使用。

创建您自己的自定义类,并实现
onDraw
方法来使用绘制图表,而不是使用fillArc

然后,您可以像使用内置组件一样将图表组件包含在布局中。

创建自己的自定义类,并实现
onDraw
方法来使用绘制图表

      public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         DemoView demoView=new DemoView(getBaseContext());
         setContentView(demoView);
      }

     private class DemoView extends View{
       public DemoView(Context context){
        super(context);
       }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        RectF mBigOval = new RectF(40, 10, 280, 250);
        Paint p = new Paint();
        DashPathEffect dashPath = new DashPathEffect(new float[]{5,5}, (float)1.0);
        PathEffect path=new PathEffect();
        p.setPathEffect(path);
        p.setStyle(Style.FILL_AND_STROKE);
        p.setColor(android.graphics.Color.GREEN);
        canvas.drawArc(mBigOval, 0, 360, true, p);
        p.setColor(Color.RED);
        canvas.drawArc(mBigOval, 0, 240, true, p);


        invalidate();
    }
}
然后,可以将图表组件包括在布局中,就像内置组件一样

      public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         DemoView demoView=new DemoView(getBaseContext());
         setContentView(demoView);
      }

     private class DemoView extends View{
       public DemoView(Context context){
        super(context);
       }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        RectF mBigOval = new RectF(40, 10, 280, 250);
        Paint p = new Paint();
        DashPathEffect dashPath = new DashPathEffect(new float[]{5,5}, (float)1.0);
        PathEffect path=new PathEffect();
        p.setPathEffect(path);
        p.setStyle(Style.FILL_AND_STROKE);
        p.setColor(android.graphics.Color.GREEN);
        canvas.drawArc(mBigOval, 0, 360, true, p);
        p.setColor(Color.RED);
        canvas.drawArc(mBigOval, 0, 240, true, p);


        invalidate();
    }
}
试试这个代码


试试这段代码。

我创建了一个库来完成你想要的()。

我创建了一个库来完成你想要的()。

好..+1代表我这边..thnxGood..+1代表我这边..thnx