1
多くのサンプルコードを検索しましたが、リアルタイムグラフが見つかりませんでした。サンプルグラフを作成しようとしましたが、コードに問題があります。キャンバスを作成する際には2点しか描画できませんが、私は点の配列を描く必要があります。だから私はPoints.Butの配列を作成したコードが正しく動作していません。ここでキャンバスを使用してランタイムグラフを描画する方法遅延を伴うアンドロイドで背景をペイントする方法
マイビュークラスです:
public class DemoView extends View {
private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Paint paint1 = new Paint(Paint.ANTI_ALIAS_FLAG);
int x = getHeight()/2;
int i = 0;
//graph point
int[] a = {20, 50, 40, 65, 56, 43, 22, 23, 55, 77, 76,
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 150,
150, 150, 150, 150, 150, 150, 20, 20, 20, 20, 20,
20, 20, 150, 52, 52, 52, 52, 52, 52, 52, 52, 52,
52, 52, 52, 52, 52, 52, 30, 30, 30, 30, 30, 30,
30, 30, 30, 30, 30, 100, 100, 100, 100, 100, 100,
100, 100, 100, 22, 22, 22, 22, 50, 50, 50};
public DemoView(Context context) {
super(context);
init();
}
public DemoView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public DemoView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
public void init() {
paint.setColor(Color.GREEN);
paint1.setColor(Color.RED);
}
@Override
protected synchronized void onDraw(Canvas canvas) {
super.onDraw(canvas);
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
//Identification the graph current position
canvas.drawRect(x, 0, x + 5, getHeight(), paint);
if (i != 0) {
//drawing the graph
canvas.drawLine(x, (getHeight()/2) - a[i], x + 1, (getHeight()/2) - a[i - 1], paint1);
}
i++;
// length of array value
if (i == 79) {
i = 0;
}
//repaint area
if (x > getWidth() - 25) {
if (x > getWidth() - 25) {
x = 35;
}
}
x += 2;
invalidate();
}}
活動
public class LineView extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_line_view);
}}
ビュー
<LinearLayout android:orientation="vertical"
android:layout_height="350dp"
android:layout_width="fill_parent">
<com.akasmedical.android.linedrawing.DemoView
android:layout_height="match_parent"
android:layout_width="wrap_content"/>
`
多くのライブラリがGitHubの上でそこにあります。これらのリンクを試す GraphView:https://github.com/jjoe64/GraphView EazeGraph:https://github.com/blackfizz/EazeGraph GraphViewDemo:https://github.com/jjoe64/GraphView-Demos –
追加してくださいActivityクラスを使用して、適切にデバッグすることができます。 – Lampard
は今、私ははい、あなたがit.Pleaseがそれを追加することができます@CrazyAndroid – wingsraam