-1

大家好,我正在从相机中拍摄图像并将其显示在 中ImageView,接下来单击 aButton我将使用以下代码将图像分成 9 等份

ArrayList<Bitmap>cut=new ArrayList<Bitmap>(split);
        BitmapDrawable bd=(BitmapDrawable)pic.getDrawable();
        Bitmap b=bd.getBitmap();
        Bitmap cutimage=Bitmap.createScaledBitmap(b, b.getWidth(), b.getHeight(), true);
        rows=cols= (int) Math.sqrt(split);
        hgt=b.getHeight()/rows;
        wdt=b.getWidth()/cols;



ArrayList<Bitmap> breakedimages== getIntent().getParcelableArrayListExtra("breaked image");

我将所有拆分后的图像放在 Arraylist 中,接下来如何将这些拆分后的图像移入GridView. 我必须在网格视图中以正确的顺序(实际图像)排列所有图像后,将拆分的图像混杂在一起,GridView然后应该显示吐司。

我已成功拆分图像并显示在网格视图中,接下来我无法将它们变成混乱的顺序,任何人都可以帮助我。

4

1 回答 1

0

您需要与位图一起保持原始位置。使用一个类将这些项目放在一起..

class PuzzleItem {
   Drawable puzzlepartImage;
   int correctPosition;

   public PuzzleItem(Drawable d, int index) {
      puzzlepartImage = d;
      correctPosition = index;
   }
}

ArrayList<PuzzleItem> list = new ArrayList<PuzzleItem>();
for (int i = 0; i < 9; i++) {
    list.add(new PuzzleItem(drawables[i], i)); 
}
Collections.shuffle(list);  
// create a adapter from this list and set to grid..
于 2012-09-28T06:42:15.317 回答