【发布时间】:2018-01-28 11:18:36
【问题描述】:
帮助了解问题可能是什么。我写了这段代码,里面有动作的描述:
int countPosition = 0;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
GridLayout.Spec buttonRowSpec = GridLayout.spec(i);
GridLayout.Spec buttonSpecColumn = GridLayout.spec(j);
TouchAction actionListener = new TouchAction(gridLayout, buttons, gameController);
ImageButton button = ButtonsFactory.createImageButton(this, bitmaps[i][j], countPosition, paddingImgBtn, actionListener);
countPosition++;
if (countPosition < 12)
buttons.add(button); // add each button to the collection
// add each button in the GridLayout with the specified parameters
gridLayout.addView(button, new GridLayout.LayoutParams(buttonRowSpec, buttonSpecColumn));
}
}
gridLayout.removeAllViewsInLayout(); // remove the buttons from GridLayout
Collections.shuffle(buttons); // mix the collection with the buttons
Bitmap lastImageBitmap = ImageProcessor.resizeImage(getResources(), R.drawable.locked, bitmaps[0][0].getWidth(), bitmaps[0][0].getHeight(), true);
lastButton.setImageBitmap(lastImageBitmap);
buttons.add(lastButton); // add a button with a picture lock at the very end of the collection
for (int i = 0; i < 12; i++) {
ImageButton button = buttons.get(i); // get the buttons from the mixed collection
gridLayout.addView(button); // add them to GridLayout
}
// do the validation that would be displayed correctly, but something tells me that this method is not for this!
// in SWING, JPanel has a method like validate (), decided that it's the same here, but alas, apparently not
gridLayout.invalidate();
输出的图像不是逻辑所期望的,按钮应该是混合的:
【问题讨论】:
标签: java android collections