我想以编程方式绘制一些内容以将其设置为背景ImageView
。它看起来应该像这样:
因此,它有点像饼图,但不是饼图。
我发现了一些可以画圈的东西:
ShapeDrawable biggerCircle= new ShapeDrawable( new OvalShape());
biggerCircle.setIntrinsicHeight( 60 );
biggerCircle.setIntrinsicWidth( 60);
biggerCircle.setBounds(new Rect(0, 0, 60, 60));
biggerCircle.getPaint().setColor(Color.BLUE);
ShapeDrawable smallerCircle= new ShapeDrawable( new OvalShape());
smallerCircle.setIntrinsicHeight( 10 );
smallerCircle.setIntrinsicWidth( 10);
smallerCircle.setBounds(new Rect(0, 0, 10, 10));
smallerCircle.getPaint().setColor(Color.BLACK);
smallerCircle.setPadding(50,50,50,50);
Drawable[] d = {smallerCircle,biggerCircle};
LayerDrawable composite1 = new LayerDrawable(d);
btn.setBackgroundDrawable(composite1);
我需要的是使用开始程度和结束程度来绘制彩色区域的东西。
这样有可能吗?
您可以使用库https://github.com/PhilJay/MPAndroidChart实现此目的。
在xml中添加以下内容:
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/chart"
android:layout_width="match_parent"
android:layout_height="match_parent" />
在Java代码中:
PieChart chart = (Piechart) findViewById(R.id.chart);
示例代码:
这就是使用它的样子。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句