0% found this document useful (0 votes)
4 views3 pages

Set Layout

The document outlines the process of creating a simple Android application that connects Java code with an XML layout to display a user interface. It details how to create a bitmap, link UI components, and draw shapes and text on a canvas using various colors. When a button is clicked, the app draws a red rectangle with text, a green circle, and blue lines, all displayed within an ImageView.

Uploaded by

divyafinalit
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)
4 views3 pages

Set Layout

The document outlines the process of creating a simple Android application that connects Java code with an XML layout to display a user interface. It details how to create a bitmap, link UI components, and draw shapes and text on a canvas using various colors. When a button is clicked, the app draws a red rectangle with text, a green circle, and blue lines, all displayed within an ImageView.

Uploaded by

divyafinalit
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

Set layout

setContentView([Link].activity_main);

 Connects Java code with activity_main.xml


 Displays the UI on screen

Create a Bitmap
Bitmap bg = [Link](720, 1280, [Link].ARGB_8888);

 Creates a blank image of size:


o Width: 720 px
o Height: 1280 px
 ARGB_8888 → high-quality color format

ImageView and Button


ImageView i = (ImageView) findViewById([Link]);
Button b = (Button) findViewById([Link]);

 Links Java objects with XML components


 imageView → displays drawings
 button → user clicks to draw shapes

✏️Canvas and Paint


Canvas c = new Canvas(bg);
Paint p = new Paint();

 Canvas → drawing area over the bitmap


 Paint → controls color, size, style of drawings

[Link](bg);

 Shows the bitmap inside the ImageView

Button click event


[Link](new [Link]() {
 Executes code when the button is clicked

🔴 Draw Text and Rectangle


[Link]([Link]);
[Link](35);
[Link]("Rectangle", 150, 350, p);
[Link](150, 150, 300, 300, p);

 Sets paint color to red


 Sets text size to 35
 Draws:
o Text "Rectangle"
o Rectangle using coordinates:
 Left: 150
 Top: 150
 Right: 300
 Bottom: 300

🟢 Draw Circle
[Link]([Link]);
[Link](200, 100, 50, p);

 Changes color to green


 Draws a circle:
o Center → (200, 100)
o Radius → 50

🔵 Draw Lines
[Link]([Link]);
[Link](150,150,225,75,p);
[Link](225,75,300,150,p);

 Sets color to blue


 Draws two lines forming a triangle shape

✅ Final Output
When the button is clicked, the app draws:
 🔴 A red rectangle and text
 🟢 A green circle
 🔵 Blue lines

All drawings appear inside the ImageView.

You might also like