variables - Android getting Bitmap dimensions depending on resolution of device? -
i trying create grid of multiple squares (should minesweeper grid 1 day).
now solution of getting every mine specific position using loop:
for(int = 0; < cols; i++) { for(int j = 0; j < rows; j++) { mines[i][j].setcoordinates(xcounter, ycounter); xcounter+=150; } ycounter+=150; xcounter = 0; } now 150 should display width or height of 1 square because if 1 mine on (0,0) next should on (minewidth,0) fit nice , snuggly.
but question is, how can independend of 150?
i got number trying out number makes grid without spacing. when use lower density device images smaller distance each other remain 150 pixels.
now how can independent of constant?
first thought use .getwidth() method width of bitmap stored in "mine" class. didn't work out so...
has got idea create grid independent of density device has?
you can try width , height of screen(in dp) , use factor determine width each grid..
you can add below code in application class,
displaymetrics displaymetrics = applicationcontext.getresources().getdisplaymetrics(); int absolutewidthpx = displaymetrics.widthinpixels; int abduluteheightpx = displaymetrics.heightinpixels; float scalingfactor = displaymetrics.density; now can find dp values width , height of screen,
/** pixels = densityindependantpixels * (dotsperinch/160), based on **/ int dpwidth = (int)(absolutewidthpx /scalingfactor); int dpheight = (int)(abduluteheightpx /scalingfactor); once have width , height in dp can try using factors determine width each grid.
Comments
Post a Comment