Why do I have to draw the small squares is not show??
I want to achieve square button control, free to move in the screen, with the main code, a great god, please answer:
/////////////////////////////////////////////////////////
Public class block extends the View {
Paint Paint.//drawing
Paint paint1.//drawing
Final int width=780;
Final int height=1560;
Final int space=60;//width between
Int vertz=0;//lateral
Int hortz=0;//vertical
int i,j;
Canvas canv;//define the canvas (background)
Private Bitmap mBitmap;//define the bitmap
Int a=0, b=0, c=60, d=60;
Public block (Context Context, int width, int height) {
Super (context);
Paint=new paint ();
Paint. SetColor (Color. YELLOW);//set the color of the line drawing
Paint. SetStrokeJoin (paint. Join. ROUND).//set the style of the joint
Paint. SetStrokeCap (paint. Cap. ROUND).//line style
Paint. SetStrokeWidth (3);//line width
Paint1=new Paint ();
Paint1. SetColor (Color. GREEN);//set the color of the line drawing
//declare the bitmap
MBitmap=Bitmap. CreateBitmap (width, height, Bitmap. Config. ARGB_8888);
//declare the canvas
Canv=new Canvas (mBitmap);
}
Protected void ontouch (final Canvas Canvas) {
Canvas. DrawBitmap (mBitmap, 0, 0, null);
//set the color of the grid lines
Canvas. DrawColor (Color. GRAY);
//set of grid lines long, wide
For (j=0; J & lt; 27. J++) {
Canvas. DrawLine (0, vertz, width, vertz, paint);
Vertz +=space;
}
for(i=0; I<14. I++) {
Canvas. DrawLine (hortz, 0, hortz, height, paint);
Hortz +=space;
}
}
Public void Beijing (Canvas, Canvas)
{
Canvas. DrawBitmap (mBitmap, 0, 0, null);
//set the color of the grid lines
Canvas. DrawColor (Color. GRAY);
//set of grid lines long, wide
For (j=0; J & lt; 27. J++) {
Canvas. DrawLine (0, vertz, width, vertz, paint);
Vertz +=space;
}
for(i=0; I<14. I++) {
Canvas. DrawLine (hortz, 0, hortz, height, paint);
Hortz +=space;
}
}
}
/////////////////////////////////////////////////////////////////
Public class MainActivity extends AppCompatActivity {
Private FrameLayout FrameLayout;
Private block block1;
Private ImageView imgView;
@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
The setContentView (R.l ayout. Activity_main);
FrameLayout=(frameLayout) the findViewById (R.i d.F L);
ImgView=(ImageView) the findViewById (R.i d.i mgView);
Block1=new block (this, 780156);
FrameLayout. AddView (block1);
}
Public void up (View View) {
//block1 ontouch (block1 canv);
Block1. Beijing (block1. Canv);
Block1) canv) drawRect (block1. A, block1. B - 60, block1. C, block1. D - 60, block1. Paint1);
Toast. MakeText (MainActivity. This, "up", Toast. LENGTH_SHORT), show ();
}
Public void down (View View) {
//block1 ontouch (block1 canv);
Block1. Beijing (block1. Canv);
Block1) canv) drawRect (block1. A, block1. B + 60, block1. C, block1. D + 60, block1. Paint1);
Toast. MakeText (MainActivity. This, "down", Toast. LENGTH_SHORT), show ();
}
Public void left (View View) {
//block1 ontouch (block1 canv);
Block1. Beijing (block1. Canv);
Block1) canv) drawRect (block1. A - 60, block1. B, block1. C - 60, block1. D, block1. Paint1);
Toast. MakeText (MainActivity. This "left", Toast. LENGTH_SHORT), show ();
}
Public void right View (View) {
//block1 ontouch (block1 canv);
Block1. Beijing (block1. Canv);
Block1) canv) drawRect (block1. A + 60, block1. B, block1. C + 60, block1. D, block1. Paint1);
Toast. MakeText (MainActivity. This "right", Toast. LENGTH_SHORT), show ();
}
}
CodePudding user response:
You as a constructor,CodePudding user response:
Bosses can detailed say:CodePudding user response:
1, block set in setWillNotDraw (false), or ontouch won't executeMethods of 2, the up and down in the execution of block1. Canv drawing, but the new canv there is no place to display, can be set to block mark, and then ontouch callback, using callback canvs to draw
CodePudding user response: