I search a lot on this , but did not find anything that support my cause, I have view1 that is chess board.I draw view1 using canvas.Now i have another view2(element of chess rook,bishop) to be drawn on the chess board. So guide me
1).Is it possible?
2)If not then what is alternative? ,i donot want to use layout
Yes it is possible. You would have to already have the rooks, etc as drawables in your res/drawable folder, then record an X and Y coordinate in an ArrayList for the middle of each square, then draw the rooks, knights, etc at the same x and y coordinate.
Every time a piece moves, you will need to re-draw view1 and view 2 based on whatever x,y coordinate the player moved the piece to.
go here: http://developer.android.com/reference/android/graphics/Canvas.html
You could maybe use that for
drawRectin order to draw the squares on the board, and you would usedrawBitmapto draw the rooks and the knights, etc.You really don’t actually need view2. Just use one view and draw the chessboard, then on the same bitmap, draw each chess piece.
You could have more than one canvas, assuming you have more than one View. So I suppose you could make view1 draw the board, then view2 would be the pieces, but that’s really not necessary. Say you have pawn1 that is at x1,y1, and user2 moves to x2,y2, then draw a new rectangle at x1, y1 (black or white depending on where it is on the board), then re-draw the piece at x2,y2.
And you could do that on View2, but I’m not 100% sure how you would implement a second view. I guess you’d have to re-draw every piece for every move onto a new bitmap instead of recycling an old bitmap.
It would be much easier to re-draw the square then re-draw the piece at x2, y2.