Hi,
I am very new to android development and have been trying to draw a square comprised of multiple smaller rectangles of different colours... Like a Mosaic essentially.
Basically at the moment I am reading values from a file which assigns the colour to the smaller Rects. I am using a pair of nested for loops to try to draw the small Rects sequentially, line by line. However when the program finishes there is only one small Rect drawn which is the last one to be drawn and its colour corresponds to the first value read from the file.
Here is some of my code to show you what I mean:
public SnapshotDraw(Context context) {
super(context);
for(int a = 0; a < 63; a++){
for(int b = 0; b < 63; b++){
fileName = PREFIX + "2" + EXTENSION;
try {
bf = new BufferedReader(new FileReader(fileName));
tokens = new StringTokenizer(bf.readLine(), " \n");
weight = Byte.parseByte(tokens.nextToken());
x_scalar = b*MAG;
y_scalar = a*MAG;
mDrawable = new ShapeDrawable(new RectShape());
mDrawable.getPaint().setColor(colour.getColour(weight));
mDrawable.setBounds((X_OFFSET + x_scalar), (Y_OFFSET + y_scalar), ((MAG + X_OFFSET) + x_scalar), ((MAG + Y_OFFSET) + y_scalar));
} catch (FileNotFoundException ex) {
Logger.getLogger(NetworkUtilities.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(NetworkUtilities.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
protected void onDraw(Canvas canvas) {
mDrawable.draw(canvas);
}
This except is from a class which extends View and is called inside an onCreate()
method in an Activity.
I would appreciate any guidance in this and thanks in advance!!
Cheers.