Grid of Circles on Canvas (Android) -
i new android development. trying make game. in game have show grid of dots (5*6) on canvas. purpose decided first show circles of same range , show bitmaps in them. followed tutorial drawing circles. compiled code. there no error or warning there, canvas don't show circle. please suggest me should do. below given code , logcat out put.
my code file:
package com.example.circle; import android.os.bundle; import android.app.activity; import android.content.context; import android.graphics.bitmap; import android.graphics.bitmap.config; import android.graphics.canvas; import android.graphics.paint; import android.view.menu; import android.view.view; public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); } public class board extends view { paint p = new paint(); paint black=new paint(); paint blue=new paint(); int rows=5; int cols=6; bitmap [][] dot=new bitmap[rows][cols]; canvas g=new canvas(); public board(context context) { super(context); p.setargb(255, 255, 255, 255); black.setargb(255, 0, 0, 0); blue.setargb(255, 255, 0, 0); for(int y=0; y<cols; y++) { for(int x=0; x<rows; x++) { bitmap map= bitmap.createbitmap(100,100, config.rgb_565); dot[x][y]=map; g.setbitmap(dot[x][y]); g.drawcircle(50, 50, 50, black); } } } protected void ondraw(canvas canvas) { super.ondraw(canvas); canvas.drawpaint(p); for(int y=0; y<cols; y++) { for(int x=0; x<rows; x++) { canvas.drawbitmap(dot[x][y], x*100, y*100,null); } } } } @override public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.menu.main, menu); return true; } }
logcat file:
03-24 12:33:37.162: d/ipcthreadstate(28936): [dn #5] br_clear_death_notification_done cookie 0x71a620 03-24 12:33:37.165: v/mediaprovider/drmhelper(28263): synchronized permitaccessdrm(28936) return false 03-24 12:33:37.175: d/ipcthreadstate(28263): [dn #5] br_clear_death_notification_done cookie 0x87ac38 03-24 12:33:37.175: d/ipcthreadstate(233): [dn #5] br_clear_death_notification_done cookie 0x9bcd28 03-24 12:33:37.176: d/ipcthreadstate(28936): [dn #5] br_clear_death_notification_done cookie 0x71a620 03-24 12:33:37.180: v/mediaprovider/drmhelper(28263): synchronized permitaccessdrm(28936) return false 03-24 12:33:37.184: d/ipcthreadstate(28263): [dn #5] br_clear_death_notification_done cookie 0x87db38 03-24 12:33:37.184: d/ipcthreadstate(233): [dn #5] br_clear_death_notification_done cookie 0x60a430 03-24 12:33:37.186: d/ipcthreadstate(28936): [dn #5] br_clear_death_notification_done cookie 0x71a620 03-24 12:33:37.251: i/surfaceflinger(101): [surfaceflinger] frames:2, duration:1.502000, fps:1.331077 03-24 12:33:37.340: d/ipcthreadstate(28222): [dn #5] br_clear_death_notification_done cookie 0x75a150 03-24 12:33:37.341: d/ipcthreadstate(233): [dn #5] br_clear_death_notification_done cookie 0xa0c9b0 03-24 12:33:37.342: d/ipcthreadstate(28936): [dn #5] br_clear_death_notification_done cookie 0x7b20c8 03-24 12:33:37.346: i/calllogprovider(24184): match == 1 03-24 12:33:37.346: d/calllogprovider(24184): in call log providers, selectionbuilder=((type != '4')) 03-24 12:33:37.364: d/calllogprovider(24184): query count == 413 03-24 12:33:37.365: d/ipcthreadstate(24184): [dn #5] br_clear_death_notification_done cookie 0x971810 03-24 12:33:37.366: d/ipcthreadstate(233): [dn #5] br_clear_death_notification_done cookie 0xd21190 03-24 12:33:37.367: d/ipcthreadstate(28936): [dn #5] br_clear_death_notification_done cookie 0x7c7198 03-24 12:33:37.371: v/contactsprovider(24184): query begin uri [content://com.android.contacts/contacts] selection [ ]
setcontentview(r.layout.activity_main);
change
setcontentview(new board(this));
since not creating new instance of class board
, setting content, view wont added. conventional start class name capital letter.
add inside ondraw
for
loop instead of drawing bitmap.
canvas.drawcircle(50, (x + 1) * 2 * 50, (y + 1) * 2 * 50, black);
Comments
Post a Comment