-1

私は Android SDK は初めてですが、Java にはかなり精通しています。クラスのグラフ関数を作成する必要がありますが、swing を使用せずに XML で作成する方法が完全にはわかりません。助言がありますか?

4

2 に答える 2

0

棒グラフや折れ線グラフなどのグラフの表示について話している場合は、ライブラリを使用して支援することをお勧めします。ここを見てください:

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

于 2013-08-29T23:32:11.510 に答える
0

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);   
    }

}
于 2013-08-30T00:01:53.410 に答える