SlideShare a Scribd company logo
3
Most read
4
Most read
5
Most read
Exp-5
Write an application that draws basic
graphical primitives on the screen.
 Aim: To develop a Simple Android Application that
draws basic Graphical Primitives on the screen.
Creating a New project:
 Open Android Studio and then click on File -> New -
> New project.
 Then type the Application name as “ex.no.5″ and
click Next.
 Then select the Minimum SDK as shown below and
click Next.
 Then select the Empty Activity and click Next.
 Finally click Finish.
 It will take some time to build and load the project.
Designing layout for the Android Application:
Click on app -> res -> layout ->
activity_main.xml.
Now click on Text as shown below.
Then delete the code which is there
and type the code as given below.
Activity_main.xml:
1. <?xml version="1.0" encoding="utf-8"?>
2. <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res
/android"
3. android:layout_width="match_parent"
4. android:layout_height="match_parent">
5.
6. <ImageView
7. android:layout_width="match_parent"
8. android:layout_height="match_parent"
9. android:id="@+id/imageView" />
10. </RelativeLayout>
Click on app -> java -> com.example.exno5 ->
MainActivity.
MainActivity.java:
package com.example.exno5;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends Activity
{
@Override
public 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.setColor(Color.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, paint);
//To draw a Square
canvas.drawText("Square", 120, 800, paint);
canvas.drawRect(50, 850, 350, 1150, paint);
//To draw a Line
canvas.drawText("Line", 480, 800, paint);
canvas.drawLine(520, 850, 520, 1150, paint);
}
}
Write an application that draws basic graphical primitives.pptx

More Related Content

PPT
android-tutorial-for-beginner
PPT
Android Architecture
ODP
Introduction to Android App Development
PDF
UI controls in Android
PPTX
Android architecture
PPTX
Android Web app
PPTX
Cloud-Case study
PPT
Android architecture
android-tutorial-for-beginner
Android Architecture
Introduction to Android App Development
UI controls in Android
Android architecture
Android Web app
Cloud-Case study
Android architecture

What's hot (20)

PDF
Location-Based Services on Android
PPT
Introduction to Android
PPTX
Mobile application development ppt
PPTX
Android User Interface
PPTX
Mobile Application Development Services-MobileApptelligence
PPTX
Android studio ppt
PDF
Hacking Android OS
PPT
Windows Phone PPT
PPTX
AN INTRODUCTION TO MOBILE APPLICATION DEVELOPMENT
PPTX
Introduction to Android and Android Studio
PDF
Intents in Android
PPTX
Mobile operating system
PPTX
Android Operating System
PPTX
Android - Application Framework
PPTX
Introduction to Android ppt
PDF
Nodejs presentation
PDF
Web Programming Assignment
PPTX
Android app development
PPTX
Introduction to mobile application development
PPTX
Broadcast Receiver
Location-Based Services on Android
Introduction to Android
Mobile application development ppt
Android User Interface
Mobile Application Development Services-MobileApptelligence
Android studio ppt
Hacking Android OS
Windows Phone PPT
AN INTRODUCTION TO MOBILE APPLICATION DEVELOPMENT
Introduction to Android and Android Studio
Intents in Android
Mobile operating system
Android Operating System
Android - Application Framework
Introduction to Android ppt
Nodejs presentation
Web Programming Assignment
Android app development
Introduction to mobile application development
Broadcast Receiver
Ad

More from vishal choudhary (20)

PPTX
mobile application using automatin using node ja java on
PPTX
mobile development using node js and java
PPTX
Pixel to Percentage conversion Convert left and right padding of a div to per...
PPTX
esponsive web design means that your website (
PPTX
function in php using like three type of function
PPTX
data base connectivity in php using msql database
PPTX
software evelopment life cycle model and example of water fall model
PPTX
software Engineering lecture on development life cycle
PPTX
strings in php how to use different data types in string
PPTX
OPEN SOURCE WEB APPLICATION DEVELOPMENT question
PPTX
web performnace optimization using css minification
PPTX
web performance optimization using style
PPTX
Data types and variables in php for writing and databse
PPTX
Data types and variables in php for writing
PPTX
Data types and variables in php for writing
PPTX
sofwtare standard for test plan it execution
PPTX
Software test policy and test plan in development
PPTX
function in php like control loop and its uses
PPTX
introduction to php and its uses in daily
PPTX
data type in php and its introduction to use
mobile application using automatin using node ja java on
mobile development using node js and java
Pixel to Percentage conversion Convert left and right padding of a div to per...
esponsive web design means that your website (
function in php using like three type of function
data base connectivity in php using msql database
software evelopment life cycle model and example of water fall model
software Engineering lecture on development life cycle
strings in php how to use different data types in string
OPEN SOURCE WEB APPLICATION DEVELOPMENT question
web performnace optimization using css minification
web performance optimization using style
Data types and variables in php for writing and databse
Data types and variables in php for writing
Data types and variables in php for writing
sofwtare standard for test plan it execution
Software test policy and test plan in development
function in php like control loop and its uses
introduction to php and its uses in daily
data type in php and its introduction to use
Ad

Recently uploaded (20)

PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
Trump Administration's workforce development strategy
PDF
What if we spent less time fighting change, and more time building what’s rig...
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Introduction to Building Materials
PDF
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PDF
advance database management system book.pdf
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Weekly quiz Compilation Jan -July 25.pdf
Trump Administration's workforce development strategy
What if we spent less time fighting change, and more time building what’s rig...
Final Presentation General Medicine 03-08-2024.pptx
Introduction to Building Materials
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
Chinmaya Tiranga quiz Grand Finale.pdf
Supply Chain Operations Speaking Notes -ICLT Program
A powerpoint presentation on the Revised K-10 Science Shaping Paper
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Paper A Mock Exam 9_ Attempt review.pdf.
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
advance database management system book.pdf
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Final Presentation General Medicine 03-08-2024.pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx

Write an application that draws basic graphical primitives.pptx

  • 1. Exp-5 Write an application that draws basic graphical primitives on the screen.
  • 2.  Aim: To develop a Simple Android Application that draws basic Graphical Primitives on the screen.
  • 3. Creating a New project:  Open Android Studio and then click on File -> New - > New project.  Then type the Application name as “ex.no.5″ and click Next.  Then select the Minimum SDK as shown below and click Next.  Then select the Empty Activity and click Next.  Finally click Finish.  It will take some time to build and load the project.
  • 4. Designing layout for the Android Application: Click on app -> res -> layout -> activity_main.xml. Now click on Text as shown below. Then delete the code which is there and type the code as given below.
  • 5. Activity_main.xml: 1. <?xml version="1.0" encoding="utf-8"?> 2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res /android" 3. android:layout_width="match_parent" 4. android:layout_height="match_parent"> 5. 6. <ImageView 7. android:layout_width="match_parent" 8. android:layout_height="match_parent" 9. android:id="@+id/imageView" /> 10. </RelativeLayout>
  • 6. Click on app -> java -> com.example.exno5 -> MainActivity. MainActivity.java: package com.example.exno5; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; import android.widget.ImageView;
  • 7. public class MainActivity extends Activity { @Override public 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.setColor(Color.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, paint); //To draw a Square canvas.drawText("Square", 120, 800, paint); canvas.drawRect(50, 850, 350, 1150, paint); //To draw a Line canvas.drawText("Line", 480, 800, paint); canvas.drawLine(520, 850, 520, 1150, paint); } }