【问题标题】:AndroidPlot - XYplot doesn't show up on graphical layout in xmlAndroidPlot - XYplot 不显示在 xml 的图形布局中
【发布时间】:2013-06-16 21:17:46
【问题描述】:

我是 android 开发领域的新手,但是我已经完成了一些非常简单的应用程序来了解环境中的工作流程。

我在运行名为 SimpleXYPlotExample 的示例程序时遇到了困难,这里分别是代码清单、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);
        }

}

这可能是由于绘图甚至没有出现在图形布局上。这就是这段代码的样子:

http://imgur.com/qYl96Zi

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

【问题讨论】:

    标签: android xml androidplot


    【解决方案1】:

    屏幕截图似乎来自 eclipse gui 编辑器,正如异常提到的那样,它不支持 setShadowLayer 方法,因此不会呈现。这只是 Eclipse 的一个限制,而不是您的代码或库中的错误。

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

    andsroidplot.title="A Simple XYPlot Example"
    

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

    【讨论】:

    • 谢谢尼克,我得到的代码实际上是来自 bitbucket (bitbucket.org/androidplot/androidplot/src/…) 的示例代码的一部分,我会注意从现在开始向您和其他人提供堆栈跟踪,我会查看并可能迁移到您推荐的 IDE。再次感谢! (我想给你一个赞成票,但我没有足够的声誉...... =P)
    • 好尴尬!我会尽快修好。不要担心投票 - 我只是来帮忙:)
    • 实际上只是去修复错字并注意到您使用的是来自 DemoApp 目录之外的源 - 这实际上应该已被删除并且已经过时了。 (现在正在处理)接下来,您将继续使用 DemoApp 目录中的示例代码。
    猜你喜欢
    • 2011-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多