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

5038-Write An Application That Draws Basic Graphical Primitives On The Screen

The document describes an Android application that draws basic graphical primitives on the screen. It includes an activity_main.xml layout file containing a TextView, a MainActivity class that sets the content view to a custom tss_view class, and a tss_view class that overrides the onDraw method to draw shapes like rectangles, circles, text and lines on a Canvas using different colors.

Uploaded by

Justin K
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)
752 views2 pages

5038-Write An Application That Draws Basic Graphical Primitives On The Screen

The document describes an Android application that draws basic graphical primitives on the screen. It includes an activity_main.xml layout file containing a TextView, a MainActivity class that sets the content view to a custom tss_view class, and a tss_view class that overrides the onDraw method to draw shapes like rectangles, circles, text and lines on a Canvas using different colors.

Uploaded by

Justin K
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/ 2

Write an application that draws basic graphical primitives on the screen

1.activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<android.support.constraint.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:layout_width="245dp"
android:layout_height="27dp"
android:layout_marginRight="104dp"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

2.MainActivity.java

package com.example.exno_4_b_i;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(new tss_view(this));
//setContentView();
}

3.tss_view.java
package com.example.exno_4_b_i;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class tss_view extends View
{

public tss_view(Context context) {


super(context);
}
public void onDraw(Canvas tss_canvas)
{
super.draw(tss_canvas);
Paint tss_paint=new Paint();
tss_paint.setColor(Color.BLACK);
tss_canvas.drawRect(10,20,30,40,tss_paint);
tss_paint.setColor(Color.YELLOW);
tss_canvas.drawCircle(460,460,80,tss_paint);
tss_paint.setColor(Color.GREEN);
tss_canvas.drawRect(500,600,700,800,tss_paint);
tss_paint.setColor(Color.RED);
tss_paint.setTextSize(40);
tss_canvas.drawText("S.Gavaskar",8,9,tss_paint);
tss_paint.setColor(Color.GREEN);
tss_canvas.drawLine(900,1100,900,900,tss_paint);
}
}

You might also like