CSL603 Mobile Computing Lab
Sem VI
Amisha Verma
Roll No 66
EXPERIMENT 8
Title To develop a Simple Android Application that draws basic Graphical
Primitives on the screen
Pre requisite Android
Mapping with CO CSL603.5
Objective To develop Application that draws basic Graphical Primitives on the screen
Outcome Students learned application that draws basic Graphical Primitives on the
screen
Deliverables Android
Colab Link
//Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:layout_width="match_par
ent"
android:layout_height="match_par
ent"
android:id="@+id/imageView" />
</RelativeLayout>
//MainActivity.java
package com.example.myapplication;
import
androidx.appcompat.app.AppCompatActivit
y; import android.graphics.Bitmap;
import
android.graphics.Canv
as; import
android.graphics.Colo
r; import
android.graphics.Paint
;
import
android.graphics.drawable.BitmapDrawable
; import android.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends
AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Creating a Bitmap
Bitmap bg = Bitmap.createBitmap(720, 1280,
Bitmap.Config.ARGB_8888);
//Setting the Bitmap as background for the
ImageView ImageView i = (ImageView)
findViewById(R.id.imageView);
i.setBackgroundDrawable(new
BitmapDrawable(bg));
//Creating the
Canvas Object
Canvas canvas =
new Canvas(bg);
//Creating the Paint Object and set its color &
TextSize Paint paint = new Paint();
Paint paint1 =
new Paint();
Paint paint2 =
new Paint();
Paint paint3 =
new Paint();
paint.setColor(Co
lor.RED);
paint1.setColor(C
olor.BLACK);
paint2.setColor(C
olor.YELLOW);
paint3.setColor(C
olor.BLUE);
paint.setTextSize
(50);
//To draw a Rectangle
canvas.drawText("Rectangle", 420,
150, paint);
canvas.drawRect(400, 200, 650, 700, paint);
//To draw a Circle
canvas.drawText("Circle", 120,
150, paint);
canvas.drawCircle(200, 350, 150, paint1);
//To draw a Square
canvas.drawText("Square",
120, 800, paint);
canvas.drawRect(50, 850, 350, 1150, paint2);
//To draw a Line
canvas.drawText("Line", 480, 800, paint);
canvas.drawLine(520, 850, 520, 1150, paint3);
}
Conclusion Developing an application using GUI components enhances user interaction
and experience by providing a visually appealing and user-friendly interface.
By integrating elements such as TextViews, Buttons, and Event Listeners, we
enable users to interact dynamically with the application. This experiment
highlights the importance of GUI design in software development,
demonstrating how various components work together to create an engaging
and functional application.
References https://www.codingconnect.net/android-application-gui-components-font-and-
colors/
https://gr-solution.blogspot.com/2015/11/develop-application-that-uses-gui_16
.html