0% found this document useful (0 votes)
24 views5 pages

Q5

The document describes code for an Android application that draws graphical shapes like circles, rectangles and squares on a canvas. It includes XML layout code and Java code to add the shapes to an image view with different colors.

Uploaded by

Harsh Rajput
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)
24 views5 pages

Q5

The document describes code for an Android application that draws graphical shapes like circles, rectangles and squares on a canvas. It includes XML layout code and Java code to add the shapes to an image view with different colors.

Uploaded by

Harsh Rajput
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
You are on page 1/ 5

5.

Write an application that draws graphical primitives such as circle,


rectangle and square. Fill all these primitives with different colors.

XML Code::
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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">
<TextView
android:id="@+id/textView6"
android:layout_width="325dp"
android:layout_height="33dp"
android:layout_marginStart="40dp"
android:layout_marginTop="16dp"
android:text="Name : Harsh Rajput Roll Number :: 2200535"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/image"
android:layout_width="409dp"
android:layout_height="662dp"
android:layout_marginStart="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Java Code::

package com.example.androidpractical;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


Bitmap bg;
ImageView im;
@SuppressLint("ResourceAsColor")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

setContentView(R.layout.activity_main);
bg=Bitmap.createBitmap(720,1280,Bitmap.Config.RGB_565);
im=findViewById(R.id.image);
im.setImageBitmap(bg);
Canvas canvas=new Canvas(bg);
Paint paint=new Paint();
paint.setColor(Color.RED);
paint.setTextSize(50);
canvas.drawText("Rectangle",70,150,paint);
canvas.drawRect(70,200,250,700,paint);

paint.setColor(Color.BLUE);
canvas.drawText("Circle",450,150,paint);
canvas.drawCircle(500,350,150,paint);

paint.setColor(Color.GREEN);
canvas.drawText("Square",70,800,paint);
canvas.drawRect(70,850,350,1150,paint);
}
}

You might also like