【问题标题】:Program a graphing function using the Android SDK for eclipse? [closed]使用 Android SDK for eclipse 编写图形功能? [关闭]
【发布时间】:2013-08-29 23:24:46
【问题描述】:

我是 Android SDK 的新手,但非常精通 Java。我需要为一个类创建一个图形函数,但我不完全确定如何在不使用 swing 和 XML 的情况下做到这一点。有什么建议吗?

【问题讨论】:

  • 什么是类的图形函数

标签: java android xml sdk graphing


【解决方案1】:

如果您正在谈论显示条形图或折线图等图表,我建议您使用库来帮助您。看看这里:

https://stackoverflow.com/questions/424752/any-good-graphing-packages-for-android?lq=1

【讨论】:

    【解决方案2】:

    您不必使用 XML。它只是 eclipse 希望您创建 UI 的默认方式。做你想做的最好的方法是创建一个扩展视图并覆盖 ondraw 方法的类。 然后你调用 setContentView(yourclass);

    下面是一些代码示例,它只是在屏幕上画一条线,足以让您开始。

    主要活动:

    package com.example.myexample;
    
    import android.os.Bundle;
    import android.app.Activity;
    
    
    public class MainActivity extends Activity {
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        //Create class that extends view
        Example myexample = new Example(this);
    
        setContentView(myexample);
    }
    

    }

    Example 类看起来像这样:

    package com.example.myexample;
    
    import android.content.Context;
    import android.graphics.Canvas;
    import android.graphics.Paint;
    import android.view.View;
    
    public class Example extends View{
    
        //You will need to declare a variable of paint to draw
        Paint mypaint = new Paint();
    
    
        //constructor
        public Example(Context context) {
            super(context);
            // TODO Auto-generated constructor stub
        }
    
        //This is the function where you draw to the screen
        @Override
        public void onDraw (Canvas canvas){
    
    
            canvas.drawLine(25, 25, 25, 50, mypaint);   
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-20
      • 2011-10-20
      • 1970-01-01
      • 2010-09-08
      • 2012-04-30
      • 2022-06-11
      • 2011-03-31
      • 2012-03-22
      相关资源
      最近更新 更多