max theis
- Forum-Beiträge: 31
08.09.2010, 11:03:19 via Website
08.09.2010 11:03:19 via Website
Guten Morgen,
ich hab mithilfe eines Tutorials http://www.droidnova.com/playing-with-graphics-in-android-part-iii,176.html
ein Programm erstellt in dem ich ein Icon verschieben kann. Jetzt möchte ich statt mit dem Icon, auf der Canvas malen bzw. zeichnen.
Panel.java // Meine Klasse die fürs zeichnen zuständig ist.
Die onDraw muss geändert werden, in ihr muss ich den Hintergrund und die Art und Weise wie ich auf der Canvas zeichnen möchte definieren. Nur wie?
Kann mir jemand mal ein bisschen unter die Arme greifen = )
Vielen Dank.
Gruß
max
ich hab mithilfe eines Tutorials http://www.droidnova.com/playing-with-graphics-in-android-part-iii,176.html
ein Programm erstellt in dem ich ein Icon verschieben kann. Jetzt möchte ich statt mit dem Icon, auf der Canvas malen bzw. zeichnen.
Panel.java // Meine Klasse die fürs zeichnen zuständig ist.
1package com.test.graphics;
2
3import android.content.Context;
4import android.graphics.Bitmap;
5import android.graphics.BitmapFactory;
6import android.graphics.Canvas;
7import android.graphics.Color;
8import android.graphics.Paint;
9import android.graphics.Paint.Style;
10import android.view.MotionEvent;
11import android.view.SurfaceHolder;
12import android.view.SurfaceView;
13import android.view.View;
14
15public class Panel extends SurfaceView
16 implements SurfaceHolder.Callback{
17
18 private DrawThread _thread;
19 private int _x = 20;
20 private int _y = 20;
21
22 Paint paint = new Paint();
23
24
25 public Panel(Context context) {
26 super(context);
27 getHolder().addCallback(this);
28 _thread = new DrawThread(getHolder(),this);
29 setFocusable(true);
30
31
32 }
33
34
35
36 public boolean onTouchEvent (MotionEvent event){
37 _x = (int) event.getX();
38 _y = (int) event.getY();
39 return true;
40
41 }
42
43 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height){
44
45 }
46
47 public void surfaceCreated (SurfaceHolder holder){
48 _thread.setRunning(true);
49 _thread.start();
50
51 }
52
53 public void surfaceDestroyed(SurfaceHolder holder){
54 boolean retry = true;
55 _thread.setRunning(false);
56
57 while(retry){
58 try{
59 _thread.join();
60 retry = false;
61 }catch(InterruptedException e){
62 }
63
64
65 }
66
67 }
68
69
70 @Override
71 public void onDraw(Canvas canvas) {
72
73 Bitmap _scratch = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
74 canvas.drawColor(Color.BLACK);
75 canvas.drawBitmap(_scratch, _x-(_scratch.getWidth()/2), _y-(_scratch.getHeight()/2), null);
76
77 }
78
79}
2
3import android.content.Context;
4import android.graphics.Bitmap;
5import android.graphics.BitmapFactory;
6import android.graphics.Canvas;
7import android.graphics.Color;
8import android.graphics.Paint;
9import android.graphics.Paint.Style;
10import android.view.MotionEvent;
11import android.view.SurfaceHolder;
12import android.view.SurfaceView;
13import android.view.View;
14
15public class Panel extends SurfaceView
16 implements SurfaceHolder.Callback{
17
18 private DrawThread _thread;
19 private int _x = 20;
20 private int _y = 20;
21
22 Paint paint = new Paint();
23
24
25 public Panel(Context context) {
26 super(context);
27 getHolder().addCallback(this);
28 _thread = new DrawThread(getHolder(),this);
29 setFocusable(true);
30
31
32 }
33
34
35
36 public boolean onTouchEvent (MotionEvent event){
37 _x = (int) event.getX();
38 _y = (int) event.getY();
39 return true;
40
41 }
42
43 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height){
44
45 }
46
47 public void surfaceCreated (SurfaceHolder holder){
48 _thread.setRunning(true);
49 _thread.start();
50
51 }
52
53 public void surfaceDestroyed(SurfaceHolder holder){
54 boolean retry = true;
55 _thread.setRunning(false);
56
57 while(retry){
58 try{
59 _thread.join();
60 retry = false;
61 }catch(InterruptedException e){
62 }
63
64
65 }
66
67 }
68
69
70 @Override
71 public void onDraw(Canvas canvas) {
72
73 Bitmap _scratch = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
74 canvas.drawColor(Color.BLACK);
75 canvas.drawBitmap(_scratch, _x-(_scratch.getWidth()/2), _y-(_scratch.getHeight()/2), null);
76
77 }
78
79}
Die onDraw muss geändert werden, in ihr muss ich den Hintergrund und die Art und Weise wie ich auf der Canvas zeichnen möchte definieren. Nur wie?
Kann mir jemand mal ein bisschen unter die Arme greifen = )
Vielen Dank.
Gruß
max
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.