Ich versuche, Wellenform mit Canvas-Methode zu zeichnen. leider bekomme ich die aktuelle position bis zur endposition aber ich muss die volle wave zeigen um sie zu sehen.Wie zeichnet man EKG-Wellenform in Android mit Leinwand
MainActivity
public class LineView extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_line_view);
}
XML
<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"/>
`
Meine Ansicht ist hier
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 = 35, j = 35;
int i = 0;
//ECG Wave form
int[] a = {20, 50, 40, 65, 56, 43, 22, 23, 55, 77, 76, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25};
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.WHITE);
paint1.setColor(Color.RED);
}
@Override
protected synchronized void onDraw(Canvas canvas) {
super.onDraw(canvas);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (i != 0) {
//draw wave form here
canvas.drawLine(x, (getHeight()/4) - a[i], x + 1, (getHeight()/4) - a[i - 1], paint1);
System.out.println(x);
}
i++;
if (i == 22) {
i = 0;
}
//Repaint wave form
if (x > getWidth() - 25) {
canvas.drawRect(j, 0, j + 20, getHeight(), paint);
j += 4;
if (j > getWidth() - 25)
j = 35;
} else {
x += 4;
}
invalidate();
}}
Erwartete Ausgabe wie hier
Ich brauche nicht nur Strom bis zur Endposition. Ich möchte vorherige Position auch in Sicht Aktivität zeichnen.
Sie sind nicht durch Ihre Daten Punkte in 'onDraw()' –
Ich kann nicht verstehen, bitte geben Sie mir Beispielcode? –
Zeichnet Ihr Code etwas? – gtsouk