前言:对于学生的答题(学习)情况,数据是直观的表现,在实际开发中也需要涉及到大量的数据统计与分析,我们经常通过图表结合来更加直观的展现数据。
接下来,记录一下最近做的一个错题率统计与总成绩排行。整个界面是由上半部分的柱形图来展现错题记录,下半部分则是已提交(答题)人员的成绩排名。主要涉及到的几个点就是调用接口获取后台数据、数据的整理(排序)、数据的展现(包括柱形图与排行列表),我们按照开发的流程来了解。
第一步,界面设计
界面布局比较简单,直接贴代码:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.administrator.parentproject.activity.TJActivity"> <RelativeLayout android:id="@+id/relative" style="@style/TitleStyle_Relative"> <ImageView android:id="@+id/back" style="@style/TitleStyle_Back" android:layout_alignParentBottom="true" /> <TextView android:id="@+id/title_tv" style="@style/TitleStyle_Text" android:layout_centerHorizontal="true" android:singleLine="true" android:text="错题率" /> </RelativeLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="6" android:orientation="horizontal" android:layout_margin="@dimen/dp_10" android:background="@color/pink"> <com.github.mikephil.charting.charts.BarChart android:id="@+id/bar_chart" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginBottom="@dimen/dp_20"/> </LinearLayout> <LinearLayout android:layout_gravity="bottom" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="5" android:orientation="vertical&#