Android自定义饼图TTJPieChart
16lz
2021-01-26
自定义View写的TTJPieChart
自定义ViewGroup写的TTJPieChartGroup
公司项目里抽出来的,希望对大家有用,也希望大家多多指教,接下来的时间我会补充讲解如何实现(代码中有很多注释)。
先给大家项目的GitHub链接:https://github.com/15915763299/TTJPieChart
TTJPieChart
改版淘淘金中使用的PieChart
目前 MyPieChartGroup 只支持三个变量的图表,MyPieChart 没有限制。 findView 之后务必要调用 init 方法初始化饼图
使用方法(举例):
xml:
<...(包名).MyPieChartGroup android:id="@+id/my_pie_chart_group" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:background="#ffffff/> <...(包名).MyPieChart android:id="@+id/my_pie_chart" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:background="#ffffff/>
java:
int[] colors = { R.color.freezing_amount, R.color.not_receive_principal, R.color.available_balance }; float[] numbers = {5, 2, 90}; String[] titles = { R.string.freezing_amount, R.string.unreceived_amount, R.string.avaliable_amount };
// my_pie_chart_group MyPieChartGroup my_pie_chart_group = (MyPieChartGroup) findViewById(R.id.my_pie_chart_group); // 第一个参数为 titles 字体的大小, 单位:sp my_pie_chart_group.init(12, titles, colors, numbers); // my_pie_chart MyPieChart my_pie_chart = (MyPieChart) findViewById(R.id.my_pie_chart); // 第一个参数为饼图半径, 第二个参数为饼图圆弧宽度, 单位都为dip my_pie_chart.initChart(65, 25, colors, numbers); my_pie_chart.setStartPosition(180);
效果图:(橙色线条为测试的时候画上去的,代码中已注释掉)
更多相关文章
- Android(安卓)Studio Error—Gradle: 错误:编码 GBK 的不可映射
- Android中的长度单位
- Android签名过程
- Android中Message传递参数实例
- 对android:textAlignmentStyle 属性参数的理解
- 纯Java代码写登录注册页面
- 语音识别(加注释)
- 自定义Dialog位置和大小
- 使用View绘制虚线时demo,方便复习