Hello this is Mortaza Cordy.
And in this story you are going to implement the and drama fit inside our mind.
My custom view class.
First of all let me show you are instance variables.
As you can see we initialize all of these instance variables inside our constructor.
Now Vinita create another instance variable of type paint.
So let's say that it is private and it is of paper paint its name is going to be paint object name it
as paint object because the paint object is going to do the drawing and the view a custom view on the
screen.
So we need this object.
Now we need to initialize this object inside our constructor.
So after calling this Super constructor here inside our custom you constructor to initialize our paint
object we need to say paint object.
Assignment operator new paint semi-colon.
Now that we initialized our paint object we need to implement the underarm F-ed inside my custom class
because we want to draw our custom view on the screen so we must implement our drummer fit inside our
class.
So let's scroll down here.
And before the end in curly brace about my custom view class you can say on drop on we need to specify
that want what we are going to draw on the screen.
Let me show you the components the default components that the Android provides us with.
So open the activity underly minute examine here.
Now take a look at this palette section we have this button or this Tuggle button.
You can see that most of these components especially that button or the text views most of them are
rectangles.
Right.
How about creating a circular pattern or a circular text view.
We already have a rectangular button or a rectangular text view or for example this checkbox.
So if I drag a checkbox here as you can see it is in a rectangle shape right.
If you have this checkbox takes and this view here in order to specify the checkbox.
So let me deal it this component here.
Now let's go inside are my custom view that of a file and here inside this unjam if it let's create
a circle a circular component if you want to you can actually create a rectangular component or anything
you want but here you want to actually create a circle.
So first let's set this tie.
Now we can say paint up text that sets style sets.
Right now we can refer to the paint class.
So paint that's tyle that feel if you take a look at these values here we have this feel and stroke
stroke.
So let's choose feel now let's set the anti-alias attributes so let's say paint object that said anti-alias
true.
So let's hold down to come on here on a keyboard and then click on this method.
Take a look at this documentation.
Here it says anti-aliasing smooths out the edges of bodies being drawn.
But it has no impact on the interior of the shape.
OK.
So let's close this wide and here let's set the color of our circle so we can say paint object that
set color and we already created an instance variable for the view colors so we can say View color.
So now it's time to draw the circle on the screen.
Now we can say canvas we have this canvas object from this upright meter here Dot draw.
So this is a very important Smurfit draw.
So take a look at this.
If it's here we have dry text.
We have just Selker a circle which we are going to use now.
We have dropped our.
We have a bitmap.
We have color line oval.
As you can see we have draw picture.
We can draw everything that we want right at the end of this app and at the end of the story else I
am going to guide you to the official documentation.
And then you will be able to do what ever you want of your custom views.
But for now we want to use the draw circle method.
This one.
So let's use this method.
And here we need to pass some arguments.
The first one is the float circle X the x value of our shape or our view on the screen.
So I'm going to pass for for example 200 comma.
We have float circle why again.
I'm going to pass for example 200 comma.
We have the radius so we can specify a radius for our circle.
Was going to say for example 50 comma and you need to pass the paint object.
So because we say paint object now it's time to specify the text inside our circle.
So after this line of code I am going to first of all specify the color of our text so we can say paint
object that set color and here is a text color and we can also specify the position of the text inside
our circle.
So you can say paint object that set text a line you're really first to paint.
Class that line dot.
We have a center left right through the center.
Let's also specify the text size of our text inside our view.
We can say paint object that said pixel size as you can see all of these works are done by the paint
optics.
We have these text size text look and scale X on all of these methods.
So I just use this one here text size and we can say for example Fretty.
Finally we are going to draw the text inside our view.
We say canvas that draw text draw takes and here let's refer to our instance variable for the view text.
So we have this view Text Camera and we have this thart.
So for this tartlets choose the value to two hundred and forty and let's use the value 200.
As you can see it is values at these values that I've put here for the start and the end the x and y
are the same for the circle X and the circle y.
You can't change these values if you want in order to see what happens.
And here you need to pass the paint object.
So paint object.