AndroidPlot - XYplot 未显示在 xml 中的图形布局上

标签 android xml androidplot

我在 Android 开发领域相当陌生,但是我已经做了一些非常简单的应用程序来了解环境中的工作流程。

我在运行名为 SimpleXYPlotExample 的示例程序时遇到困难,这里分别是代码、 list 、main.xml 和 Activity.java。我知道这是某种用户错误,但如果有人能给我一些关于我做错了什么的有用指示,那就太好了。

起初,所有代码都被破坏了,但我意识到我忘记导入库了。现在我已经这样做了,我尝试在我的 nexus 上运行该程序,但它在输入时崩溃了。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example"
          android:versionCode="1"
          android:versionName="1.0">

    <uses-sdk
    android:minSdkVersion="6"
    android:targetSdkVersion="16"/>

    <application android:label="SimpleXYPlotExample" 
                 android:icon="@drawable/icon" 
                 android:debuggable="true"
                 android:hardwareAccelerated="false">
        <activity android:name=".MyActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest> 
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    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="150px"
    android:layout_marginTop="10px"
    android:layout_marginLeft="10px"
    android:layout_marginRight="10px"
    andsroidplot.title="A Simple XYPlot Example"
    androidplot.ticksPerRangeLabel="4"
    androidplot.ticksPerDomainLabel="2"
    androidplot.gridPadding="4dp|4dp|4dp|4dp"
    />
</LinearLayout>
    package com.example;

    import java.util.Arrays;

    import android.app.Activity;
    import android.os.Bundle;

    import com.androidplot.series.XYSeries;
    import com.androidplot.ui.AnchorPosition;
    import com.androidplot.xy.LineAndPointFormatter;
    import com.androidplot.xy.SimpleXYSeries;
    import com.androidplot.xy.XLayoutStyle;
    import com.androidplot.xy.XYPlot;
    import com.androidplot.xy.YLayoutStyle;


    public class MyActivity extends Activity
    {

        private XYPlot plot;

        @Override
        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            // initialize our XYPlot reference:
            plot = (XYPlot) findViewById(R.id.mySimpleXYPlot);

            // add a new series
            XYSeries mySeries = new SimpleXYSeries(
                    Arrays.asList(0, 25, 55, 2, 80, 30, 99, 0, 44, 6),
                    SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "series1");
            plot.addSeries(mySeries, new LineAndPointFormatter(
                    getApplicationContext(), R.xml.f1));

            // reposition the domain label to look a little cleaner:
            plot.position(plot.getDomainLabelWidget(), // the widget to position
                    45,                                // x position value, in this case 45 pixels
                    XLayoutStyle.ABSOLUTE_FROM_LEFT,   // how the x position value is applied, in this case from the left
                    0,                                 // y position value
                    YLayoutStyle.ABSOLUTE_FROM_BOTTOM, // how the y position is applied, in this case from the bottom
                    AnchorPosition.LEFT_BOTTOM);       // point to use as the origin of the widget being positioned

            plot.centerOnRangeOrigin(60);
            plot.centerOnDomainOrigin(5);
        }

}

这可能是因为绘图甚至没有显示在图形布局上。这就是这段代码的样子:

/image/T44Vo.jpg

如您所见,我已经导入了 androidplot 库。请指教。

最佳答案

屏幕截图似乎来自 eclipse gui 编辑器,作为异常(exception),它不支持 setShadowLayer 方法,因此不会渲染。这只是 Eclipse 的限制,而不是代码或库中的错误。

通常,为了能够回答有关 Androidplot 崩溃原因的问题,您需要提供相应的堆栈跟踪。不过我确实注意到你的 xml 中有这个拼写错误:

andsroidplot.title="A Simple XYPlot Example"

就获得一个可用的所见即所得编辑器而言,我个人的建议是尝试一下 IntelliJ IDEA 或 Android Studio(基于当前 EAP 版本的 IntelliJ IDEA 构建)。两者都是免费的,而且都在(恕我直言)更高级的 IDE 中。

关于AndroidPlot - XYplot 未显示在 xml 中的图形布局上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17206482/

相关文章:

android - 使用 Android 智能手机的 Wi-Fi HotSpot 进行 Chromecast

sql-server - SSIS WebService 任务插入 XML header

android - AndroidPlot 的 ProGuard 配置

java - 无法在 android studio 中解析 : com. android.support:design:27

java - 当我旋转模拟器时,如何阻止我的 Activity 被破坏?

Android studio 2.3.3 无法写入模拟器的外部存储

python - BS4 获取 XML 标签变量

python - 使用 xmltodict 从已解析的 xml 文件的键中删除特殊字符

AndroidPlot - 显示垂直域标签

android - Android 中的动态图形渲染