0% found this document useful (0 votes)
7 views2 pages

Android Traffic Sign Drawing App

This document contains code for an Android application that displays traffic signs. It defines a TrafficView class that extends the View class and overrides the onDraw method. The onDraw method draws different colored ovals representing traffic signs like red, yellow and green within defined RectF bounds on the canvas using various Paint objects. It also draws rectangles and text using the Paint objects. The MainActivity class sets the TrafficView as the content view to display the traffic signs.

Uploaded by

Ehab Zaben
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Android Traffic Sign Drawing App

This document contains code for an Android application that displays traffic signs. It defines a TrafficView class that extends the View class and overrides the onDraw method. The onDraw method draws different colored ovals representing traffic signs like red, yellow and green within defined RectF bounds on the canvas using various Paint objects. It also draws rectangles and text using the Paint objects. The MainActivity class sets the TrafficView as the content view to display the traffic signs.

Uploaded by

Ehab Zaben
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Key solution : Traffic sign

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


TrafficView tView;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
tView = new TrafficView(this);

setContentView(tView);
}
}
class TrafficView extends View

{ public TrafficView(Context context)


{ super(context); }

@Override

protected void onDraw (Canvas canvas)


{
[Link](canvas);

RectF oval1 = new RectF(100, 100, 350,350);


RectF oval2 = new RectF(100, 350, 350,600);
RectF oval3 = new RectF(100, 600, 350,850);
RectF rect1 = new RectF(50,50,400,900);
RectF rect2 = new RectF(200,900,250,1500);
Paint paint = new Paint();
[Link]([Link]);
Paint p1 = new Paint();
[Link]([Link]);
Paint p2 = new Paint();
[Link]([Link]);
Paint p3 = new Paint();
[Link]([Link]);
[Link]("Parent", 30, 50, p1);
[Link]("Parent", 30, 50, p2);
[Link]("Parent", 30, 50, p3);
[Link]("Parent", 30, 50, paint);
[Link](rect2, paint);
[Link](rect1, paint);
[Link](oval1, p1);
[Link](oval2, p2);
[Link](oval3, p3);

}
}

You might also like