Home > Mobile >  Android studio inherited View MyView increase. Java still need those configurations to draw figure??
Android studio inherited View MyView increase. Java still need those configurations to draw figure??

Time:09-23

Online learning knowledge is very fragmented,
Android studio inherited View MyView increase. Java still need those configurations to draw figure??
Looking for a lot of article, can inherit inheriting ViewV, found a paragraph and create MyView. Java
Figure, also need the mechanism to chart and out, and a lot of article will a piece, the remaining configuration does not speak,
The trouble,,,,,,,,, speak in detail??????
Thank you very much!

CodePudding user response:

Do you want to draw in the ontouch method

CodePudding user response:

Public class MainActivity extends AppCompatActivity
{
@ Override
Protected void onCreate (Bundle savedInstanceState)
{
Super. OnCreate (savedInstanceState);
The setContentView (R.l ayout. Activity_main);
}
Protected void ontouch (Canvas, Canvas)
{
Super. Ontouch (canvas);//hint compiler error error: can't find the symbolic symbols: method ontouch (Canvas)
}
}

CodePudding user response:

Ontouch is of the View class, you customize the View

CodePudding user response:

//1) add a CLASS CLASS
Package com. Example. Myapplication;

import android.content.Context;
import android.graphics.Canvas;
The import android. Graphics. Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

Public class MyCanvas extends the View
{
Public MyCanvas Context (Context)
{
Super (context);
}

//a parameter
Public MyCanvas (Context Context, AttributeSet attrs)
{
Super (context, attrs);
}

@ Override
Protected void ontouch (Canvas, Canvas) {
Super. Ontouch (canvas);

//create the brush
Paint p=new Paint ();
//set solid
P. etStyle (Paint. Style. The FILL);
//set red
P. etColor (Color BLACK);
//set the sawtooth effect of brush
P. etAntiAlias (true);
//draw
Canvas. DrawRect (50, 100, 300, 300, p);

}


}
////////////////////////////////////////////////
In the main window button

Public class MainActivity extends AppCompatActivity
{
@ Override
Protected void onCreate (Bundle savedInstanceState)
{
Super. OnCreate (savedInstanceState);
The setContentView (R.l ayout. Activity_main);


}
Public void btnSumClick View (View)
{
StartActivity (new Intent (this, MyCanvas. Class));

}

}
//to press the button to exit the?????????????????????

CodePudding user response:

Create a VIEW class

Why executed directly exit??? 3 "version of the

CodePudding user response:

The most simple demonstration, create rectangle on the screen, expanded the class VIEW, MyCanvas. Java compiler through no problem,
In the main window MainActivity. Java add a button, want to draw a rectangle, after pressing the call the MyCanvas. Java rewrite the view class for drawing,
But after the button press event
Public void btnSumClick View (View)
{
StartActivity (new Intent (this, MyCanvas. Class));

}

Reference MyCanvas. Java rewrite the view class for drawing out, is this what mechanism, where is the problem??? , thank you! Got seven to eight days, thank you!
  • Related