0

我正在尝试使用android绘图库,只需复制示例页面的代码

http://androidplot.com/docs/quickstart/

我添加了库源,并在示例代码中更改了以下行,因为它给了我一个错误:

// Create a formatter to use for drawing a series using LineAndPointRenderer
    // and configure it from xml:
    LineAndPointFormatter series1Format = new LineAndPointFormatter();
    series1Format.setPointLabelFormatter(new PointLabelFormatter());
    series1Format.configure(getApplicationContext(),
            R.xml.line_point_formatter_with_plf1);

我将最后一行更改为:

R.layout.line_point_formatter_with_plf1);

该程序需要几分钟才能编译并给出很多错误,如下所示

Android Dex:[prueba graficos] (org.eclipse.ui.internal.ide.IDEWorkbenchErrorHandler$1) 不附带

Android Dex:[prueba graficos] 关联的 EnclosureMethod 属性。这个类可能是由一个

Android Dex:[prueba graficos] 并且没有指定任何“-target”类型选项。忽视的后果

我的样式也有错误,在示例中样式为 style="@style/sample_activity" 但我没有那种样式,所以我只设置了布局大小。

并在 layout/xml/line_point_formatter_with_plf1.xml

<?xml version="1.0" encoding="utf-8"?>
<config
    linePaint.strokeWidth="3dp"
    linePaint.color="#00AA00"
    vertexPaint.color="#007700"
    fillPaint.color="#00000000"
    pointLabelFormatter.textPaint.color="#FFFFFF"/>

config algo 这个词给了我一个错误:应该定义 layout_height 属性。

4

1 回答 1

4

实际上,您提供的教程中有一个小错误:文件 line_point_formatter_plf1.xml 和 line_point_formatter_plf2.xml 应该在文件夹 res/xml/ 下,如果 res/ 文件夹下没有 xml 文件夹,只需创建它,它将接受配置标签没有问题。

这是因为您将它们放在 layout/ 下,所以它认为它们是布局文件,并告诉您 'config' 标记为根对于布局 xml 文件是不可接受的。

对于“应定义layout_height”属性”错误,只需添加这两行:

    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

到 simple_xy_plot_example.xml 文件的根标签(此错误与 config 标签无关)

您的 simple_xy_plot_example.xml 文件应如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              style="@style/AppTheme"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent">

    <com.androidplot.xy.XYPlot
            android:id="@+id/mySimpleXYPlot"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            androidPlot.title="A Simple XY Plot"
            androidPlot.domainLabel="Domain"
            androidPlot.rangeLabel="Range"
            androidPlot.titleWidget.labelPaint.textSize="@dimen/title_font_size"
            androidPlot.domainLabelWidget.labelPaint.textSize="@dimen/domain_label_font_size"
            androidPlot.rangeLabelWidget.labelPaint.textSize="@dimen/range_label_font_size"
            androidPlot.graphWidget.marginTop="20dp"
            androidPlot.graphWidget.marginLeft="15dp"
            androidPlot.graphWidget.marginBottom="25dp"
            androidPlot.graphWidget.marginRight="10dp"
            androidPlot.graphWidget.rangeLabelPaint.textSize="@dimen/range_tick_label_font_size"
            androidPlot.graphWidget.rangeOriginLabelPaint.textSize="@dimen/range_tick_label_font_size"
            androidPlot.graphWidget.domainLabelPaint.textSize="@dimen/domain_tick_label_font_size"
            androidPlot.graphWidget.domainOriginLabelPaint.textSize="@dimen/domain_tick_label_font_size"
            androidPlot.legendWidget.textPaint.textSize="@dimen/legend_text_font_size"
            androidPlot.legendWidget.iconSizeMetrics.heightMetric.value="15dp"
            androidPlot.legendWidget.iconSizeMetrics.widthMetric.value="15dp"
            androidPlot.legendWidget.heightMetric.value="25dp"
            androidPlot.legendWidget.positionMetrics.anchor="right_bottom"
            androidPlot.graphWidget.gridLinePaint.color="#000000"/>
</LinearLayout>

我试过了,对我来说效果很好。

于 2013-09-07T05:41:51.210 回答