-1

こんにちは皆さん、私はカメラから画像を取得し、ImageView次のButtonコードを使用して画像を 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");

そして、分割されたすべての画像を A​​rraylist に配置してから、これらの分割された画像を移動する方法を次に示します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 に答える