我从阿森纳复制火花样本。 但是我无法编辑它。 这是我的火花图。
这是我的代码。
我想展示x轴,但我无法解决这个问题。
public class ConeFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_main_profile_c1, container, false);
SparkView sparkView = (SparkView) view.findViewById(R.id.sparkview);
SparkView sparkView1 = (SparkView) view.findViewById(R.id.sparkview1);
adapter = new RandomizedAdapter();
sparkView.setAdapter(adapter);
adapter1 = new RandomizedAdapter();
sparkView1.setAdapter(adapter1);
public static class RandomizedAdapter extends SparkAdapter {
private final float[] yData;
private final Random random;
public RandomizedAdapter() {
random = new Random();
yData = new float[5];
randomize();
}
public void randomize() {
for (int i = 0, count = yData.length; i < count; i++) {
yData[i] = random.nextFloat();
}
notifyDataSetChanged();
}
@Override
public int getCount() {
return yData.length;
}
@Override
public Object getItem(int index) {
return yData[index];
}
@Override
public float getY(int index)
{
return yData[index];
}
}
我的XML在这里。
<com.and.wodness.spark.SparkView
android:id="@+id/sparkview"
android:layout_width="150dp"
android:layout_height="70dp"
app:spark_lineColor="@color/colorProgress"
app:spark_lineWidth="3dp"
app:spark_scrubEnabled="true"
app:spark_animateChanges="true"/>
<com.and.wodness.spark.SparkView
android:id="@+id/sparkview1"
android:layout_width="150dp"
android:layout_height="70dp"
app:spark_lineColor="@color/colorDarkRed"
app:spark_lineWidth="3dp"
app:spark_scrubEnabled="true"
app:spark_animateChanges="true"/>