How to draw some lines in a view element defined in the xml layout
- by Nils
Hello,
I have problems drawing some simple lines in a view object (Android programming).
First I created the layout with the view element(kind of painting area) in it (XML file).
[...]
< View
android:id="@+id/viewmap"
android:layout_width="572px"
android:layout_height="359px"
android:layout_x="26px"
android:layout_y="27px"
[...]
... and tried then to access it to draw some lines. Unfortunately the program is running and other UI elements like buttons are displayed, but I can't see the drawings. What's wrong ?
[...]
viewmap = (View) findViewById(R.id.viewmap);
Canvas canvas = new Canvas();
viewmap.draw(canvas);
Paint p = new Paint();
p.setColor(Color.BLUE);
p.setStyle(Paint.Style.STROKE);
canvas.drawColor(Color.WHITE);
p.setColor(Color.BLUE);
canvas.drawLine(4, 4, 29, 5, p);
p.setColor(Color.RED);
viewmap.draw(canvas);
[...]
Thanks for help :) !